1 ! Copyright (C) 2022 CapitalEx
2 ! See http://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 sets sorting
6 splitting tools.test unicode vocabs vocabs.loader ;
11 USING: arrays io kernel math math.parser sets
12 hashtables sequences vocabs ;
13 IN: lint.vocabs.testing
24 : test-four ( x -- x )
28 : test-five ( x -- ? )
33 CONSTANT: ignore-postpone-using "POSTPONE: USING: : nop ( -- ) ;"
34 CONSTANT: ingore-\-using "\\ USING: : nop ( -- ) ;"
35 CONSTANT: ignore-postpone-use "POSTPONE: USE: ignore : nop ( -- ) ;"
36 CONSTANT: ignore-\-use "\\ USE: ignore : nop ( -- ) ;"
37 CONSTANT: ignore-in-string-one "\"USE:\" \"USING:\" : nop ( -- ) ;"
38 CONSTANT: ignore-in-string-two "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
39 CONSTANT: ignore-in-string-three "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
40 CONSTANT: ignore-in-string-four "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
41 CONSTANT: ignore-use-regex "R/ USE: ignore/ : nop ( -- ) ;"
42 CONSTANT: ignore-using-regex "R/ USING: ignore ;/ : nop ( -- ) ;"
43 CONSTANT: empty-using-statement "USING: ; nop ( -- ) ;"
44 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
47 "It should work on multiple lines, with multiple imports across the file: " print
49 { { "hashtables" "math.primes" "sequences" "sets" "vocabs" } } [ mock-file find-unused-in-string ] unit-test
53 "It should ignore USE: and USING: that have been postponed: " print
54 { { } } [ ignore-postpone-using find-unused-in-string ] unit-test
55 { { } } [ ingore-\-using find-unused-in-string ] unit-test
56 { { } } [ ignore-postpone-use find-unused-in-string ] unit-test
57 { { } } [ ignore-\-use find-unused-in-string ] unit-test
61 "It should ignore USE: and USING: that are in strings: " print
62 { { } } [ ignore-in-string-one find-unused-in-string ] unit-test
63 { { } } [ ignore-in-string-two find-unused-in-string ] unit-test
64 { { } } [ ignore-in-string-three find-unused-in-string ] unit-test
65 { { } } [ ignore-in-string-four find-unused-in-string ] unit-test
69 "It should ignore USE: and USING: that are in RegEx: " print
70 { { } } [ ignore-use-regex find-unused-in-string ] unit-test
71 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
75 "IT should return empty when no imports have been found: " print
76 { { } } [ empty-using-statement find-unused-in-string ] unit-test
80 "It should forget vocabs that aren't already loaded: " print
81 dictionary get clone 1array [
82 "USE: bitcoin.client" find-unused-in-string drop