|
| 1 | +import fs from 'node:fs'; |
| 2 | +import { test, expect, describe } from 'vitest'; |
| 3 | + |
| 4 | +import { |
| 5 | + FILE_LOCATION, |
| 6 | + NUMERIC_INPUT, |
| 7 | + ANALLIFY_INPUT, |
| 8 | + STRINGIFY_INPUT, |
| 9 | + RUN_WRONG_OUTPUT, |
| 10 | + ANAL_FILE_LOCATION, |
| 11 | + EMPTY_STRING_INPUT, |
| 12 | + RUN_CORRECT_OUTPUT, |
| 13 | + ANALLIFY_WRONG_OUTPUT, |
| 14 | + STRINGIFY_WRONG_OUTPUT, |
| 15 | + COMPILE_CORRECT_OUTPUT, |
| 16 | + COMPILED_FILE_LOCATION, |
| 17 | + ANALLIFY_CORRECT_OUTPUT, |
| 18 | + STRINGIFY_CORRECT_OUTPUT, |
| 19 | +} from './seeds.js'; |
| 20 | + |
| 21 | +import { |
| 22 | + run, |
| 23 | + anallify, |
| 24 | + stringify, |
| 25 | + compile, |
| 26 | +} from '../lib/std.js'; |
| 27 | +import { ERROR } from '../lib/dictionary.js'; |
| 28 | + |
| 29 | +describe('Anallify', () => { |
| 30 | + test('Encode string to anal', () => { |
| 31 | + expect(anallify(ANALLIFY_INPUT)).toBe(ANALLIFY_CORRECT_OUTPUT); |
| 32 | + expect(anallify(ANALLIFY_INPUT)).not.toBe(ANALLIFY_WRONG_OUTPUT); |
| 33 | + }); |
| 34 | + |
| 35 | + test('Throw error if argument is not a string', () => { |
| 36 | + expect(() => anallify(1)).toThrowError(Error(ERROR.notString)); |
| 37 | + }); |
| 38 | + |
| 39 | + test('Throw error if argument is missing', () => { |
| 40 | + expect(() => anallify(EMPTY_STRING_INPUT)).toThrowError( |
| 41 | + Error(ERROR.missingArgument), |
| 42 | + ); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +describe('Stringify', () => { |
| 47 | + test('Decode anal to string', () => { |
| 48 | + expect(stringify(STRINGIFY_INPUT)).toBe(STRINGIFY_CORRECT_OUTPUT); |
| 49 | + expect(stringify(STRINGIFY_INPUT)).not.toBe(STRINGIFY_WRONG_OUTPUT); |
| 50 | + }); |
| 51 | + |
| 52 | + test('Throw error if argument is not a string', () => { |
| 53 | + expect(() => stringify(NUMERIC_INPUT)).toThrowError( |
| 54 | + Error(ERROR.notString), |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + test('Throw error if argument is missing', () => { |
| 59 | + expect(() => stringify(EMPTY_STRING_INPUT)).toThrowError( |
| 60 | + Error(ERROR.missingArgument), |
| 61 | + ); |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
| 65 | +describe('Run', () => { |
| 66 | + test('Run .anal file', () => { |
| 67 | + expect(run(ANAL_FILE_LOCATION)).toBe(RUN_CORRECT_OUTPUT); |
| 68 | + expect(run(ANAL_FILE_LOCATION)).not.toBe(RUN_WRONG_OUTPUT); |
| 69 | + }); |
| 70 | + |
| 71 | + test('Throw error if file is not found', () => { |
| 72 | + expect(() => run(EMPTY_STRING_INPUT)).toThrowError( |
| 73 | + Error(ERROR.fileNotFound), |
| 74 | + ); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +describe('Compile', () => { |
| 79 | + test('Compile file to .anal', () => { |
| 80 | + expect(compile(FILE_LOCATION)).toBe(COMPILE_CORRECT_OUTPUT); |
| 81 | + fs.rmSync(COMPILED_FILE_LOCATION); |
| 82 | + }); |
| 83 | + |
| 84 | + test('Throw error if file is not found', () => { |
| 85 | + expect(() => compile(EMPTY_STRING_INPUT)).toThrowError( |
| 86 | + Error(ERROR.fileNotFound), |
| 87 | + ); |
| 88 | + }); |
| 89 | +}); |
0 commit comments