Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Migrate to Typescript #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 80
}
32 changes: 0 additions & 32 deletions __test__/example/e2e-test.js

This file was deleted.

35 changes: 35 additions & 0 deletions __test__/example/e2e-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { exec } from 'child_process';

interface Options {
interpreter?: string;
target?: string;
contain?: string;
}
const defaultOptions: Options = {
interpreter: 'jaksel-interpreter.ts',
target: 'example/example1.jaksel',
contain: null
};
export function e2eRunFile(options: Options, doneCallback: jest.DoneCallback) {
if (!options || typeof options !== 'object') {
// default options
options = defaultOptions;
}
const selectedOption = { ...defaultOptions };
Object.assign(selectedOption, options);
exec(
`yarn ts-node ${selectedOption.interpreter} ${selectedOption.target}`,
(err, stdout, stderr) => {
if (stdout) {
expect(stdout).toContain(selectedOption.contain);
}
if (err) {
doneCallback(err);
}
if (stderr) {
doneCallback(err);
}
doneCallback();
}
);
}
12 changes: 0 additions & 12 deletions __test__/example/example1.test.js

This file was deleted.

14 changes: 14 additions & 0 deletions __test__/example/example1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { e2eRunFile as e2eTest } from './e2e-test';

describe('End To End Test example 1', () => {
it('Should return as expected value', (done) => {
e2eTest(
{
target: 'example/example1.jaksel',
contain:
'Umur lu 21\nElu tua\nKalo gua umurnya 31\ngua lebih tua\nUdahan ah\n'
},
done
);
});
});
39 changes: 0 additions & 39 deletions __test__/logics/parser/conditionIf.test.js

This file was deleted.

35 changes: 35 additions & 0 deletions __test__/logics/parser/conditionIf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import conditionIf from '../../../lib/logics/parser/conditionIf';
import getTsFormat from '../test-parser-helper';

describe('Test Condition If', () => {
it('Should parse string correctly', () => {
const test1 = conditionIf("kalo foo itu 'bar'");
expect(test1.exp).toBe(`if (foo == 'bar')`);
});

it('Should parse number correctly', () => {
const test1 = conditionIf('kalo foo itu 123');
expect(test1.exp).toBe(`if (foo == 123)`);
});

it('Should return null if not match', () => {
const test1 = conditionIf('kal foo itu 123');
const test2 = conditionIf('kaloo foo i 123');
expect(test1).toBe(null);
expect(test2).toBe(null);
});

it('Should return correctly flexing', () => {
const jsFormat = getTsFormat(`
kalo foo itu 123
spill "its 123"
udahan
`);
expect(jsFormat).not.toBeNull();
const shouldMatch = ['if (foo == 123) {', 'console.log("its 123")', '}'];
jsFormat.split('\n').every((v, i) => {
if (!shouldMatch[i]) return true;
return expect(v).toContain(shouldMatch[i]);
});
});
});
31 changes: 0 additions & 31 deletions __test__/logics/parser/consoleLog.test.js

This file was deleted.

31 changes: 31 additions & 0 deletions __test__/logics/parser/consoleLog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import consoleLog from '../../../lib/logics/parser/consoleLog';
import getTsFormat from '../test-parser-helper';

describe('Test Console log', () => {
it('Should parse string correctly', () => {
const test1 = consoleLog(`spill "Hello world"`);
expect(test1.exp).toBe(`console.log("Hello world");`);
});

it('Should parse number correctly', () => {
const test1 = consoleLog('spill 123');
expect(test1.exp).toBe(`console.log(123);`);
});

it('Should return null if not match', () => {
const test1 = consoleLog('spil 123');
const test2 = consoleLog('spilll false');
expect(test1).toBe(null);
expect(test2).toBe(null);
});

it('Should return correctly flexing', () => {
const jsFormat = getTsFormat(`
literally foo itu "Hello world"
spill foo
`);
expect(jsFormat).not.toBeNull();
expect(jsFormat).toContain(`let foo = "Hello world";`);
expect(jsFormat).toContain(`console.log(foo);`);
});
});
37 changes: 0 additions & 37 deletions __test__/logics/parser/constAssign.test.js

This file was deleted.

34 changes: 34 additions & 0 deletions __test__/logics/parser/constAssign.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import constAssign from '../../../lib/logics/parser/constAssign';
import getTsFormat from '../test-parser-helper';

describe('Test Const assign', () => {
it('Should parse string correctly', () => {
const test1 = constAssign("seriously foo itu 'bar'");
expect(test1.exp).toBe(`const foo = 'bar';`);
});

it('Should parse number correctly', () => {
const test1 = constAssign('seriously foo itu 123');
expect(test1.exp).toBe(`const foo = 123;`);
});

it('Should return null if not match', () => {
const test1 = constAssign('serisly foo tu 123');
const test2 = constAssign('seriouly foo tu 123');
expect(test1).toBe(null);
expect(test2).toBe(null);
});

it('Should return correctly flexing', () => {
const jsFormat = getTsFormat(`
seriously foo itu 123
spill foo
`);
expect(jsFormat).not.toBeNull();
const shouldMatch = ['const foo = 123', 'console.log(foo)'];
jsFormat.split('\n').every((v, i) => {
if (!shouldMatch[i]) return true;
return expect(v).toContain(shouldMatch[i]);
});
});
});
25 changes: 0 additions & 25 deletions __test__/logics/parser/loopForOf.test.js

This file was deleted.

25 changes: 25 additions & 0 deletions __test__/logics/parser/loopForOf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import loopForOf from '../../../lib/logics/parser/loopForOf';
import getTsFormat from '../test-parser-helper';

describe('Test var assign', () => {
it('Should return null if not match', () => {
const test1 = loopForOf('fomo semu foo dari bar');
const test2 = loopForOf('fomo smua foo dar bar');
expect(test1).toBe(null);
expect(test2).toBe(null);
});

it('Should return correctly flexing', () => {
const jsFormat = getTsFormat(`
fomo semua foo dari bar
spill foo
udahan
`);
expect(jsFormat).not.toBeNull();
const shouldMatch = ['for (const foo of bar) {', 'console.log(foo)', '}'];
jsFormat.split('\n').every((v, i) => {
if (!shouldMatch[i]) return true;
return expect(v).toContain(shouldMatch[i]);
});
});
});
Loading