1- import { test , expect } from 'vitest' ;
1+ import { test , expect , describe } from 'vitest' ;
22
33import {
44 ANALLIFY_INPUT ,
@@ -16,19 +16,69 @@ import {
1616 run ,
1717 anallify ,
1818 stringify ,
19+ compile ,
1920} from '../lib/stdlib.js' ;
21+ import { ERROR } from '../lib/dictionary.js' ;
2022
21- test ( 'Encode string to anal' , ( ) => {
22- expect ( anallify ( ANALLIFY_INPUT ) ) . toBe ( ANALLIFY_CORRECT_OUTPUT ) ;
23- expect ( anallify ( ANALLIFY_INPUT ) ) . not . toBe ( ANALLIFY_WRONG_OUTPUT ) ;
23+ describe ( 'Anallify' , ( ) => {
24+ test ( 'Encode string to anal' , ( ) => {
25+ expect ( anallify ( ANALLIFY_INPUT ) ) . toBe ( ANALLIFY_CORRECT_OUTPUT ) ;
26+ expect ( anallify ( ANALLIFY_INPUT ) ) . not . toBe ( ANALLIFY_WRONG_OUTPUT ) ;
27+ } ) ;
28+
29+ test ( 'Throw error if argument is not a string' , ( ) => {
30+ expect ( ( ) => anallify ( 1 ) ) . toThrowError ( Error ( ERROR . notString ) ) ;
31+ } ) ;
32+
33+ test ( 'Throw error if argument is missing' , ( ) => {
34+ expect ( ( ) => anallify ( '' ) ) . toThrowError ( Error ( ERROR . missingArgument ) ) ;
35+ } ) ;
2436} ) ;
2537
26- test ( 'Decode anal to string' , ( ) => {
27- expect ( stringify ( STRINGIFY_INPUT ) ) . toBe ( STRINGIFY_CORRECT_OUTPUT ) ;
28- expect ( stringify ( STRINGIFY_INPUT ) ) . not . toBe ( STRINGIFY_WRONG_OUTPUT ) ;
38+ describe ( 'Stringify' , ( ) => {
39+ test ( 'Decode anal to string' , ( ) => {
40+ expect ( stringify ( STRINGIFY_INPUT ) ) . toBe ( STRINGIFY_CORRECT_OUTPUT ) ;
41+ expect ( stringify ( STRINGIFY_INPUT ) ) . not . toBe ( STRINGIFY_WRONG_OUTPUT ) ;
42+ } ) ;
43+
44+ test ( 'Decode with correct chars' , ( ) => {
45+ const ANAL_CHARACTERS = 'anal' ;
46+ const charCodeA = STRINGIFY_INPUT . length ;
47+ const charCodeB = STRINGIFY_INPUT . length * 2 ;
48+
49+ const anal = `${ ANAL_CHARACTERS . repeat ( charCodeA ) } ${ ANAL_CHARACTERS . repeat ( charCodeB ) } ` ;
50+ const result = stringify ( anal ) ;
51+
52+ expect ( result ) . toBe ( String . fromCharCode ( charCodeA ) + String . fromCharCode ( charCodeB ) ) ;
53+ } ) ;
54+
55+ test ( 'Throw error if argument is not a string' , ( ) => {
56+ expect ( ( ) => stringify ( 1 ) ) . toThrowError ( Error ( ERROR . notString ) ) ;
57+ } ) ;
58+
59+ test ( 'Throw error if argument is missing' , ( ) => {
60+ expect ( ( ) => stringify ( '' ) ) . toThrowError ( Error ( ERROR . missingArgument ) ) ;
61+ } ) ;
2962} ) ;
3063
31- test ( 'Run .anal file' , ( ) => {
32- expect ( run ( ANAL_FILE_LOCATION ) ) . toBe ( RUN_CORRECT_OUTPUT ) ;
33- expect ( run ( ANAL_FILE_LOCATION ) ) . not . toBe ( RUN_WRONG_OUTPUT ) ;
64+ describe ( 'Run' , ( ) => {
65+ test ( 'Run .anal file' , ( ) => {
66+ expect ( run ( ANAL_FILE_LOCATION ) ) . toBe ( RUN_CORRECT_OUTPUT ) ;
67+ expect ( run ( ANAL_FILE_LOCATION ) ) . not . toBe ( RUN_WRONG_OUTPUT ) ;
68+ } ) ;
69+
70+ test ( 'Throw error if file is not found' , ( ) => {
71+ expect ( ( ) => run ( '' ) ) . toThrowError ( Error ( ERROR . fileNotFound ) ) ;
72+ } ) ;
73+ } ) ;
74+
75+ describe ( 'Compile' , ( ) => {
76+ test ( 'Compile .anal file' , ( ) => {
77+ expect ( compile ( ANAL_FILE_LOCATION ) ) . toBe ( RUN_CORRECT_OUTPUT ) ;
78+ expect ( compile ( ANAL_FILE_LOCATION ) ) . not . toBe ( RUN_WRONG_OUTPUT ) ;
79+ } ) ;
80+
81+ test ( 'Throw error if file is not found' , ( ) => {
82+ expect ( ( ) => run ( '' ) ) . toThrowError ( Error ( ERROR . fileNotFound ) ) ;
83+ } ) ;
3484} ) ;
0 commit comments