-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add run and compile commands to stdlib
- Loading branch information
1 parent
714b87d
commit 38f580b
Showing
8 changed files
with
98 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
#!/usr/bin/env node | ||
import help from './lib/help.js'; | ||
import { anallify, stringify } from './lib/stdlib.js'; | ||
import { HELP, STRINGIFY, ANALLIFY } from './lib/constants.js'; | ||
|
||
import { | ||
run, | ||
compile, | ||
anallify, | ||
stringify, | ||
} from './lib/stdlib.js'; | ||
|
||
import { | ||
RUN, | ||
HELP, | ||
COMPILE, | ||
ANALLIFY, | ||
STRINGIFY, | ||
} from './lib/constants.js'; | ||
|
||
function cli() { | ||
let output = ''; | ||
const command = process.argv[2]; | ||
const args = process.argv.slice(3, process.argv.length).join(''); | ||
|
||
switch (command) { | ||
case COMPILE: compile(args); break; | ||
case RUN: output = run(args); break; | ||
case HELP: process.stdout.write(help); break; | ||
case ANALLIFY: output = anallify(args); break; | ||
case STRINGIFY: output = stringify(args); break; | ||
default: process.stdout.write(help); break; | ||
} | ||
|
||
process.stdout.write(output); | ||
process.stdout.write(`${output}\n`); | ||
} | ||
|
||
cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const RUN = 'run'; | ||
export const HELP = 'help'; | ||
export const COMPILE = 'compile'; | ||
export const ANALLIFY = 'anallify'; | ||
export const STRINGIFY = 'stringify'; | ||
export const ANAL_CHARACTERS = 'ππ'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const ERROR = { | ||
fileNotFound: 'File not found.', | ||
missingArgument: 'Missing argument.', | ||
notString: 'Only strings are accepted', | ||
}; | ||
|
||
export const SUCCESS = { | ||
compileSuccess: 'Compilation completed successfully.', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import { test, expect } from 'vitest'; | ||
|
||
import * as seed from './seeds.js'; | ||
import { anallify, stringify } from '../lib/stdlib.js'; | ||
import { | ||
ANALLIFY_INPUT, | ||
STRINGIFY_INPUT, | ||
RUN_WRONG_OUTPUT, | ||
ANAL_FILE_LOCATION, | ||
RUN_CORRECT_OUTPUT, | ||
ANALLIFY_WRONG_OUTPUT, | ||
STRINGIFY_WRONG_OUTPUT, | ||
ANALLIFY_CORRECT_OUTPUT, | ||
STRINGIFY_CORRECT_OUTPUT, | ||
} from './seeds.js'; | ||
|
||
import { | ||
run, | ||
anallify, | ||
stringify, | ||
} from '../lib/stdlib.js'; | ||
|
||
test('Encode string to anal', () => { | ||
expect(anallify(seed.ANALLIFY_INPUT)).toBe(seed.ANALLIFY_CORRECT_OUTPUT); | ||
expect(anallify(seed.ANALLIFY_INPUT)).not.toBe(seed.ANALLIFY_WRONG_OUTPUT); | ||
expect(anallify(ANALLIFY_INPUT)).toBe(ANALLIFY_CORRECT_OUTPUT); | ||
expect(anallify(ANALLIFY_INPUT)).not.toBe(ANALLIFY_WRONG_OUTPUT); | ||
}); | ||
|
||
test('Decode anal to string', () => { | ||
expect(stringify(seed.STRINGIFY_INPUT)).toBe(seed.STRINGIFY_CORRECT_OUTPUT); | ||
expect(stringify(seed.STRINGIFY_INPUT)).not.toBe(seed.STRINGIFY_WRONG_OUTPUT); | ||
expect(stringify(STRINGIFY_INPUT)).toBe(STRINGIFY_CORRECT_OUTPUT); | ||
expect(stringify(STRINGIFY_INPUT)).not.toBe(STRINGIFY_WRONG_OUTPUT); | ||
}); | ||
|
||
test('Run .anal file', () => { | ||
expect(run(ANAL_FILE_LOCATION)).toBe(RUN_CORRECT_OUTPUT); | ||
expect(run(ANAL_FILE_LOCATION)).not.toBe(RUN_WRONG_OUTPUT); | ||
}); |