(import scheme) (import (chicken base)) (import test) (import minlight) (load-built-in-languages) (test-group "C programs" (test "Empty program" '() (lex-string "c" "")) (test "Whitespace" '((chunk " ")) (lex-string "c" " ")) (test "Line comment" '((comment "// Hello world!")) (lex-string "cpp" "// Hello world!")) (test "Line comments" '((comment "// Hello world!\n") (comment "//Hello again!")) (lex-string "c++" "// Hello world!\n//Hello again!")) (test "Multiline comments" '((comment "/* Hello world! /* Hello again!*/") (chunk "\n{}")) (lex-string "c" "/* Hello world! /* Hello again!*/\n{}")) (test "Just an #include" '((keyword "#include") (chunk " ")) (lex-string "c" "#include ")) (test "#ifdef dance" '((keyword "#if") (chunk " 0\ncomment\n") (keyword "#endif")) (lex-string "c" "#if 0\ncomment\n#endif")) (test "Local #include" '((keyword "#include") (chunk " ") (string "\"util.h\"")) (lex-string "c" "#include \"util.h\"")) (test "String escapes" '((string "\"foo\\\"bar\"")) (lex-string "c" "\"foo\\\"bar\""))) (test-group "diffs and patches" (test "Vanilla diff" '((chunk "20c20\n< \"angstrom\"\n") (keyword "---") (chunk "\n> \"angstrom\" {< \"0.14.0\"}\n")) (lex-string "diff" "20c20\n< \"angstrom\"\n---\n> \"angstrom\" {< \"0.14.0\"}\n")) (test "Unified diff" '((keyword "---") (chunk " a/comby.opam 2020-06-28 10:55:04.613475248 +0200\n") (keyword "+++") (chunk " b/comby.opam 2020-06-28 10:55:30.163117496 +0200\n") (keyword "@@") (chunk " -17,7 +17,7 ") (keyword "@@") (chunk " depends: [\n \"mparser-comby\"\n \"ppxlib\"\n \"ppx_deriving\"\n- \"angstrom\"\n+ \"angstrom\" {< \"0.14.0\"}\n \"hack_parallel\"\n \"opium\"\n \"pcre\"\n")) (lex-string "diff" "--- a/comby.opam 2020-06-28 10:55:04.613475248 +0200\n+++ b/comby.opam 2020-06-28 10:55:30.163117496 +0200\n@@ -17,7 +17,7 @@ depends: [\n \"mparser-comby\"\n \"ppxlib\"\n \"ppx_deriving\"\n- \"angstrom\"\n+ \"angstrom\" {< \"0.14.0\"}\n \"hack_parallel\"\n \"opium\"\n \"pcre\"\n")) (test "Git patch" '((keyword "diff --git") (chunk " a/comby.opam b/comby.opam\n") (keyword "index") (chunk " 7470e54..f40af7d 100644\n") (keyword "---") (chunk " a/comby.opam\n") (keyword "+++") (chunk " b/comby.opam\n") (keyword "@@") (chunk " -17,7 +17,7 ") (keyword "@@") (chunk " depends: [\n \"mparser-comby\"\n \"ppxlib\"\n \"ppx_deriving\"\n- \"angstrom\"\n+ \"angstrom\" {< \"0.14.0\"}\n \"hack_parallel\"\n \"opium\"\n \"pcre\"\n")) (lex-string "patch" "diff --git a/comby.opam b/comby.opam\nindex 7470e54..f40af7d 100644\n--- a/comby.opam\n+++ b/comby.opam\n@@ -17,7 +17,7 @@ depends: [\n \"mparser-comby\"\n \"ppxlib\"\n \"ppx_deriving\"\n- \"angstrom\"\n+ \"angstrom\" {< \"0.14.0\"}\n \"hack_parallel\"\n \"opium\"\n \"pcre\"\n"))) (test-group "Elisp programs" (test "Hello world" '((chunk "(message ") (string "\"Hello world!\"") (chunk ")")) (lex-string "elisp" "(message \"Hello world!\")")) (test "Comment" '((comment ";; Here be dragons")) (lex-string "elisp" ";; Here be dragons")) (test "Defmacro" '((chunk "(defmacro ignore (") (keyword "&rest") (chunk " body) ") (keyword "nil") (chunk ")")) (lex-string "elisp" "(defmacro ignore (&rest body) nil)"))) (test-group "Makefiles" (test "Commentary" '((comment "# Bootstrapping right is difficult because of the circular dependencies.")) (lex-string "make" "# Bootstrapping right is difficult because of the circular dependencies.")) (test "Printf" '((chunk "printf ") (string "\"Hello world!\n\"") (chunk ";")) (lex-string "make" "printf \"Hello world!\n\";")) (test "Rule" '((chunk "CC ") (keyword "?=") (chunk " cc\n%.o: %.c\n\t$(CC) ") (keyword "$<") (chunk " -o ") (keyword "$@")) (lex-string "make" "CC ?= cc\n%.o: %.c\n\t$(CC) $< -o $@"))) (test-group "Python programs" (test "File processing" '((keyword "with") (chunk " ") (keyword "open") (chunk "(") (string "'/etc/passwd'") (chunk ") ") (keyword "as") (chunk " f:\n ") (keyword "pass") (chunk " ") (comment "# comment")) (lex-string "python" "with open('/etc/passwd') as f:\n pass # comment")) (test "Docstring" '((keyword "def") (chunk " test():\n ") (string "\"\"\"\nDocumentation\n\"\"\"") (chunk "\n ") (keyword "pass")) (lex-string "python" "def test():\n \"\"\"\nDocumentation\n\"\"\"\n pass"))) (test-group "Scheme programs" (test "Hello world" '((chunk "(define (hello)\n (display ") (string "\"Hello world!\"") (chunk ")\n ") (comment ";; display doesn't include an implicit newline\n") (chunk " (newline))")) (lex-string "scheme" "(define (hello)\n (display \"Hello world!\")\n ;; display doesn't include an implicit newline\n (newline))")) (test "DSSSL" '((chunk "(define (test ") (keyword "#!optional") (chunk " foo ") (keyword "#!key") (chunk " bar ") (keyword "#!rest") (chunk " baz) ") (keyword "#!eof") (chunk ")")) (lex-string "scheme" "(define (test #!optional foo #!key bar #!rest baz) #!eof)")) (test "Nested comments" '((comment "#| (broken #| (code #| (bad) |#) |#) |#")) (lex-string "scheme" "#| (broken #| (code #| (bad) |#) |#) |#")) (test "Crazy nested comments" '((comment "#| 1 #| 2 |# 1 #| 2 #| 3 |# 2 |# 1 |#")) (lex-string "scheme" "#| 1 #| 2 |# 1 #| 2 #| 3 |# 2 |# 1 |#"))) (test-group "Shell scripts" (test "hashbang" '((comment "#!/bin/sh")) (lex-string "sh" "#!/bin/sh")) (test "Interactivity test" '((keyword "if") (chunk " [ -z ") (string "\"$PS1\"") (chunk " ]; ") (keyword "then") (chunk "\n ") (keyword "echo") (chunk " This shell is not interactive\n") (keyword "fi")) (lex-string "bash" "if [ -z \"$PS1\" ]; then\n echo This shell is not interactive\nfi")) (test "Session" '((chunk "[wasa@box ~]") (keyword "$") (chunk " lss\nbash: lss: ") (keyword "command") (chunk " not found\n[wasa@box ~]") (keyword "$") (chunk " ") (keyword "echo") (chunk " ") (keyword "$?") (chunk "\n127")) (lex-string "shell-session" "[wasa@box ~]$ lss\nbash: lss: command not found\n[wasa@box ~]$ echo $?\n127"))) (test-group "INI configurations" (test "Config block" '((chunk "[options]\n") (comment "# Foo\n") (chunk "bar = 1")) (lex-string "ini" "[options]\n# Foo\nbar = 1"))) (test-group "Plain text" (test "No comments or strings highlighting" '((chunk "# Python \n// C++ \n\"String\" + ' other';")) (lex-string "text" "# Python \n// C++ \n\"String\" + ' other';")) (test "All-caps keywords" '((keyword "TODO") (chunk ": Write a todo list\n") (keyword "FIXME") (chunk " Everything else")) (lex-string "text" "TODO: Write a todo list\nFIXME Everything else"))) (test-exit)