@@ -830,233 +830,3 @@ pub const LexProcess = struct {
830
830
if (self .arg_str_buf != null ) self .arg_str_buf .? .deinit ();
831
831
}
832
832
};
833
-
834
- test "LexProcess initialization" {
835
- const ifilepath = "LexProcess_initialization.fn" ;
836
- const ofilepath = "LexProcess_initialization.c" ;
837
- // Mock input file
838
- {
839
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
840
- defer file .close ();
841
- const input = "dummy" ;
842
- try file .writeAll (input );
843
- }
844
-
845
- const allocator = std .testing .allocator ;
846
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
847
- var lex_proc = LexProcess .init (& transpile_proc );
848
-
849
- defer transpile_proc .deinit ();
850
- defer lex_proc .deinit ();
851
-
852
- try std .testing .expect (transpile_proc .tokens .items ().len == 0 );
853
- try std .testing .expect (lex_proc .transpile_proc == & transpile_proc );
854
- try std .testing .expect (lex_proc .curr_exp_count == 0 );
855
- try std .testing .expect (lex_proc .parenthesis_buf == null );
856
- try std .testing .expect (lex_proc .arg_str_buf == null );
857
-
858
- // Delete test files
859
- try fs .cwd ().deleteFile (ifilepath );
860
- try fs .cwd ().deleteFile (ofilepath );
861
- }
862
-
863
- test "LexProcess next_char" {
864
- const ifilepath = "LexProcess_next_char.fn" ;
865
- const ofilepath = "LexProcess_next_char.c" ;
866
- // Mock input file
867
- {
868
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
869
- defer file .close ();
870
- const input = "abc\n " ;
871
- try file .writeAll (input );
872
- }
873
-
874
- const allocator = std .testing .allocator ;
875
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
876
- var lex_proc = LexProcess .init (& transpile_proc );
877
-
878
- defer transpile_proc .deinit ();
879
- defer lex_proc .deinit ();
880
-
881
- try std .testing .expectEqual ('a' , (try lex_proc .next_char ()).? );
882
- try std .testing .expectEqual ('b' , (try lex_proc .next_char ()).? );
883
- try std .testing .expectEqual ('c' , (try lex_proc .next_char ()).? );
884
- try std .testing .expectEqual ('\n ' , (try lex_proc .next_char ()).? );
885
- try std .testing .expect (try lex_proc .next_char () == null );
886
-
887
- // Delete test files
888
- try fs .cwd ().deleteFile (ifilepath );
889
- try fs .cwd ().deleteFile (ofilepath );
890
- }
891
-
892
- test "LexProcess peek_char" {
893
- const ifilepath = "LexProcess_peek_char.fn" ;
894
- const ofilepath = "LexProcess_peek_char.c" ;
895
- // Mock input file
896
- {
897
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
898
- defer file .close ();
899
- const input = "abc" ;
900
- try file .writeAll (input );
901
- }
902
-
903
- const allocator = std .testing .allocator ;
904
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
905
- var lex_proc = LexProcess .init (& transpile_proc );
906
-
907
- defer transpile_proc .deinit ();
908
- defer lex_proc .deinit ();
909
-
910
- try std .testing .expectEqual ('a' , (try lex_proc .peek_char ()).? );
911
- try std .testing .expectEqual ('a' , (try lex_proc .peek_char ()).? );
912
- _ = try lex_proc .next_char ();
913
- try std .testing .expectEqual ('b' , (try lex_proc .peek_char ()).? );
914
-
915
- // Delete test files
916
- try fs .cwd ().deleteFile (ifilepath );
917
- try fs .cwd ().deleteFile (ofilepath );
918
- }
919
-
920
- test "LexProcess push_char" {
921
- const ifilepath = "LexProcess_push_char.fn" ;
922
- const ofilepath = "LexProcess_push_char.c" ;
923
- // Mock input file
924
- {
925
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
926
- defer file .close ();
927
- const input = "abc" ;
928
- try file .writeAll (input );
929
- }
930
-
931
- const allocator = std .testing .allocator ;
932
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
933
- var lex_proc = LexProcess .init (& transpile_proc );
934
-
935
- defer transpile_proc .deinit ();
936
- defer lex_proc .deinit ();
937
-
938
- _ = try lex_proc .next_char ();
939
- _ = try lex_proc .next_char ();
940
- try lex_proc .push_char ('b' );
941
- try std .testing .expectEqual ('b' , (try lex_proc .next_char ()).? );
942
-
943
- // Delete test files
944
- try fs .cwd ().deleteFile (ifilepath );
945
- try fs .cwd ().deleteFile (ofilepath );
946
- }
947
-
948
- test "LexProcess comment" {
949
- const ifilepath = "LexProcess_comment.fn" ;
950
- const ofilepath = "LexProcess_comment.c" ;
951
- // Mock input file
952
- {
953
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
954
- defer file .close ();
955
- const input = "// This is a comment\n " ;
956
- try file .writeAll (input );
957
- }
958
-
959
- const allocator = std .testing .allocator ;
960
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
961
- var lex_proc = LexProcess .init (& transpile_proc );
962
-
963
- defer transpile_proc .deinit ();
964
- defer lex_proc .deinit ();
965
-
966
- try lex_proc .lex ();
967
- const t = transpile_proc .tokens .items ()[0 ];
968
- try std .testing .expectEqual (t .type , .Comment );
969
- try std .testing .expectEqualStrings (" This is a comment" , t .data .sval .items );
970
-
971
- // Delete test files
972
- try fs .cwd ().deleteFile (ifilepath );
973
- try fs .cwd ().deleteFile (ofilepath );
974
- }
975
-
976
- test "LexProcess string" {
977
- const ifilepath = "LexProcess_string.fn" ;
978
- const ofilepath = "LexProcess_string.c" ;
979
- // Mock input file
980
- {
981
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
982
- defer file .close ();
983
- const input = "\" Hello, World!\" " ;
984
- try file .writeAll (input );
985
- }
986
-
987
- const allocator = std .testing .allocator ;
988
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
989
- var lex_proc = LexProcess .init (& transpile_proc );
990
-
991
- defer transpile_proc .deinit ();
992
- defer lex_proc .deinit ();
993
-
994
- try lex_proc .lex ();
995
- const t = transpile_proc .tokens .items ()[0 ];
996
- try std .testing .expectEqual (t .type , .String );
997
- try std .testing .expectEqualStrings ("Hello, World!" , t .data .sval .items );
998
-
999
- // Delete test files
1000
- try fs .cwd ().deleteFile (ifilepath );
1001
- try fs .cwd ().deleteFile (ofilepath );
1002
- }
1003
-
1004
- test "LexProcess number" {
1005
- const ifilepath = "LexProcess_number.fn" ;
1006
- const ofilepath = "LexProcess_number.c" ;
1007
- // Mock input file
1008
- {
1009
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
1010
- defer file .close ();
1011
- const input = "12345" ;
1012
- try file .writeAll (input );
1013
- }
1014
-
1015
- const allocator = std .testing .allocator ;
1016
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
1017
- var lex_proc = LexProcess .init (& transpile_proc );
1018
-
1019
- defer transpile_proc .deinit ();
1020
- defer lex_proc .deinit ();
1021
-
1022
- try lex_proc .lex ();
1023
- const t = transpile_proc .tokens .items ()[0 ];
1024
- try std .testing .expectEqual (t .type , .Number );
1025
- try std .testing .expectEqual (t .data .llnum , 12345 );
1026
-
1027
- // Delete test files
1028
- try fs .cwd ().deleteFile (ifilepath );
1029
- try fs .cwd ().deleteFile (ofilepath );
1030
- }
1031
-
1032
- test "LexProcess lex" {
1033
- const ifilepath = "LexProcess_lex.fn" ;
1034
- const ofilepath = "LexProcess_lex.c" ;
1035
- // Mock input file
1036
- {
1037
- const file = try fs .cwd ().createFile (ifilepath , .{ .read = true });
1038
- defer file .close ();
1039
- const input = "123 + 456 // comment\n \" string\" " ;
1040
- try file .writeAll (input );
1041
- }
1042
-
1043
- const allocator = std .testing .allocator ;
1044
- var transpile_proc = try codegen .TranspileProcess .init (allocator , ifilepath , ofilepath , .{ .outf = true });
1045
- var lex_proc = LexProcess .init (& transpile_proc );
1046
-
1047
- defer transpile_proc .deinit ();
1048
- defer lex_proc .deinit ();
1049
-
1050
- try lex_proc .lex ();
1051
-
1052
- try std .testing .expectEqual (6 , transpile_proc .tokens .items ().len );
1053
- try std .testing .expectEqual (transpile_proc .tokens .items ()[0 ].type , .Number );
1054
- try std .testing .expectEqual (transpile_proc .tokens .items ()[1 ].type , .Operator );
1055
- try std .testing .expectEqual (transpile_proc .tokens .items ()[2 ].type , .Number );
1056
- try std .testing .expectEqual (transpile_proc .tokens .items ()[3 ].type , .Comment );
1057
- try std .testing .expectEqual (transpile_proc .tokens .items ()[4 ].type , .NewLine );
1058
- try std .testing .expectEqual (transpile_proc .tokens .items ()[5 ].type , .String );
1059
- // Delete test files
1060
- try fs .cwd ().deleteFile (ifilepath );
1061
- try fs .cwd ().deleteFile (ofilepath );
1062
- }
0 commit comments