1- import { test , expect , describe , is } from 'vitest' ;
1+ import fs from 'node:fs' ;
2+ import { test , expect , describe } from 'vitest' ;
23
34import {
5+ FILE_LOCATION ,
6+ NUMERIC_INPUT ,
47 ANALLIFY_INPUT ,
58 STRINGIFY_INPUT ,
69 RUN_WRONG_OUTPUT ,
710 ANAL_FILE_LOCATION ,
11+ EMPTY_STRING_INPUT ,
812 RUN_CORRECT_OUTPUT ,
913 ANALLIFY_WRONG_OUTPUT ,
1014 STRINGIFY_WRONG_OUTPUT ,
15+ COMPILE_CORRECT_OUTPUT ,
16+ COMPILED_FILE_LOCATION ,
1117 ANALLIFY_CORRECT_OUTPUT ,
1218 STRINGIFY_CORRECT_OUTPUT ,
1319} from './seeds.js' ;
@@ -17,7 +23,7 @@ import {
1723 anallify ,
1824 stringify ,
1925 compile ,
20- } from '../lib/stdlib .js' ;
26+ } from '../lib/std .js' ;
2127import { ERROR } from '../lib/dictionary.js' ;
2228
2329describe ( 'Anallify' , ( ) => {
@@ -31,7 +37,9 @@ describe('Anallify', () => {
3137 } ) ;
3238
3339 test ( 'Throw error if argument is missing' , ( ) => {
34- expect ( ( ) => anallify ( '' ) ) . toThrowError ( Error ( ERROR . missingArgument ) ) ;
40+ expect ( ( ) => anallify ( EMPTY_STRING_INPUT ) ) . toThrowError (
41+ Error ( ERROR . missingArgument ) ,
42+ ) ;
3543 } ) ;
3644} ) ;
3745
@@ -41,23 +49,16 @@ describe('Stringify', () => {
4149 expect ( stringify ( STRINGIFY_INPUT ) ) . not . toBe ( STRINGIFY_WRONG_OUTPUT ) ;
4250 } ) ;
4351
44- test ( 'Decode with correct chars' , ( ) => {
45- const ANAL_CHARACTERS = '' ;
46- const charCodeA = ANAL_CHARACTERS . length ;
47- const charCodeB = ANAL_CHARACTERS . length * 2 ;
48-
49- const anal = `${ ANAL_CHARACTERS . repeat ( charCodeA ) } ${ ANAL_CHARACTERS . repeat ( charCodeB ) } ` ;
50-
51- const result = stringify ( anal ) ;
52- expect ( result ) . toBe ( String . fromCharCode ( charCodeA ) + String . fromCharCode ( charCodeB ) ) ;
53- } ) ;
54-
5552 test ( 'Throw error if argument is not a string' , ( ) => {
56- expect ( ( ) => stringify ( 1 ) ) . toThrowError ( Error ( ERROR . notString ) ) ;
53+ expect ( ( ) => stringify ( NUMERIC_INPUT ) ) . toThrowError (
54+ Error ( ERROR . notString ) ,
55+ ) ;
5756 } ) ;
5857
5958 test ( 'Throw error if argument is missing' , ( ) => {
60- expect ( ( ) => stringify ( '' ) ) . toThrowError ( Error ( ERROR . missingArgument ) ) ;
59+ expect ( ( ) => stringify ( EMPTY_STRING_INPUT ) ) . toThrowError (
60+ Error ( ERROR . missingArgument ) ,
61+ ) ;
6162 } ) ;
6263} ) ;
6364
@@ -68,12 +69,21 @@ describe('Run', () => {
6869 } ) ;
6970
7071 test ( 'Throw error if file is not found' , ( ) => {
71- expect ( ( ) => run ( '' ) ) . toThrowError ( Error ( ERROR . fileNotFound ) ) ;
72+ expect ( ( ) => run ( EMPTY_STRING_INPUT ) ) . toThrowError (
73+ Error ( ERROR . fileNotFound ) ,
74+ ) ;
7275 } ) ;
7376} ) ;
7477
7578describe ( 'Compile' , ( ) => {
79+ test ( 'Compile file to .anal' , ( ) => {
80+ expect ( compile ( FILE_LOCATION ) ) . toBe ( COMPILE_CORRECT_OUTPUT ) ;
81+ fs . rmSync ( COMPILED_FILE_LOCATION ) ;
82+ } ) ;
83+
7684 test ( 'Throw error if file is not found' , ( ) => {
77- expect ( ( ) => compile ( '' ) ) . toThrowError ( Error ( ERROR . fileNotFound ) ) ;
85+ expect ( ( ) => compile ( EMPTY_STRING_INPUT ) ) . toThrowError (
86+ Error ( ERROR . fileNotFound ) ,
87+ ) ;
7888 } ) ;
7989} ) ;
0 commit comments