1 ! Copyright (C) 2022 CapitalEx
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs compiler.units continuations
4 formatting hash-sets hashtables io io.encodings.utf8 io.files
5 kernel namespaces regexp sequences sequences.deep
6 sequences.parser sets sorting splitting tools.test unicode
12 USING: arrays io kernel math math.parser sets
13 hashtables sequences vocabs ;
14 IN: lint.vocabs.testing
25 : test-four ( x -- x )
29 : test-five ( x -- ? )
34 CONSTANT: ignore-postpone-using "POSTPONE: USING: : nop ( -- ) ;"
35 CONSTANT: ingore-\-using "\\ USING: : nop ( -- ) ;"
36 CONSTANT: ignore-postpone-use "POSTPONE: USE: ignore : nop ( -- ) ;"
37 CONSTANT: ignore-\-use "\\ USE: ignore : nop ( -- ) ;"
38 CONSTANT: ignore-in-string-one "\"USE:\" \"USING:\" : nop ( -- ) ;"
39 CONSTANT: ignore-in-string-two "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
40 CONSTANT: ignore-in-string-three "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
41 CONSTANT: ignore-in-string-four "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
42 CONSTANT: ignore-string-with-quote "\"\\\"USE:\" : nop ( -- ) ;"
43 CONSTANT: ignore-use-regex "R/ USE: ignore/ : nop ( -- ) ;"
44 CONSTANT: ignore-using-regex "R/ USING: ignore ;/ : nop ( -- ) ;"
45 CONSTANT: ignore-char-backslash "CHAR: \\ USING: math.functions ;"
46 CONSTANT: empty-using-statement "USING: ; nop ( -- ) ;"
47 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
50 "next-token should get the next non-blank string in the stream:" print
51 { "hello" } [ "hello world!" <sequence-parser> next-token ] unit-test
52 { "hello" } [ "\n hello \n world! " <sequence-parser> next-token ] unit-test
56 "next-token should ignore comments:" print
57 { "world!" } [ "! hello\nworld!" <sequence-parser> next-token ] unit-test
58 { "world!" } [ "! h\n! e\n! l\n! l\n! o\nworld!" <sequence-parser> next-token ] unit-test
62 "It should work on multiple lines, with multiple imports across the file: " print
64 { { "hashtables" "math.primes" "sequences" "sets" "vocabs" } } [ mock-file find-unused-in-string ] unit-test
68 "It should ignore USE: and USING: that have been postponed: " print
69 { { } } [ ignore-postpone-using find-unused-in-string ] unit-test
70 { { } } [ ingore-\-using find-unused-in-string ] unit-test
71 { { } } [ ignore-postpone-use find-unused-in-string ] unit-test
72 { { } } [ ignore-\-use find-unused-in-string ] unit-test
76 "It should ignore USE: and USING: that are in strings: " print
77 { { } } [ ignore-in-string-one find-unused-in-string ] unit-test
78 { { } } [ ignore-in-string-two find-unused-in-string ] unit-test
79 { { } } [ ignore-in-string-three find-unused-in-string ] unit-test
80 { { } } [ ignore-in-string-four find-unused-in-string ] unit-test
81 { { } } [ ignore-string-with-quote find-unused-in-string ] unit-test
85 "It should ignore CHAR: \\: " print
86 { { "math.functions" } } [ ignore-char-backslash find-unused-in-string ] unit-test
90 "It should ignore USE: and USING: that are in RegEx: " print
91 { { } } [ ignore-use-regex find-unused-in-string ] unit-test
92 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
96 "It should return empty when no imports have been found: " print
97 { { } } [ empty-using-statement find-unused-in-string ] unit-test
101 "It should forget vocabs that aren't already loaded: " print
102 dictionary get clone 1array [
103 "USE: bitcoin.client" find-unused-in-string drop