|
14 | 14 |
|
15 | 15 | import unittest |
16 | 16 |
|
| 17 | +from utest.resources import datafilereader |
17 | 18 | from wx import stc |
18 | | -from robotide.editor.lex_detect import detect |
| 19 | +from robotide.editor.lex_detect import detect, detect_from_file |
19 | 20 |
|
20 | 21 | PLUGIN_NAME = "Text Edit" |
21 | 22 |
|
@@ -82,6 +83,38 @@ def test_valid_detections(self): |
82 | 83 | print(f"\nResults: {passed} passed, {failed} failed out of {len(tests)} tests") |
83 | 84 | assert failed == 0 |
84 | 85 |
|
| 86 | + def test_invalid_detections(self): |
| 87 | + ftests = [ ("Cargo.toml", None), # stc.STC_LEX_TOML |
| 88 | + ("app.dart", None), # stc.STC_LEX_DART |
| 89 | + ("main.zig", None), # stc.STC_LEX_ZIG |
| 90 | + ("game.gd", None), # stc.STC_LEX_GDSCRIPT |
| 91 | + ("prog.nim", None), # stc.STC_LEX_NIM |
| 92 | + ("app.jl", None), # stc.STC_LEX_JULIA |
| 93 | + # ASCIIDOC exists in Scintilla/wxWidgets but not in wxPython |
| 94 | + ("readme.adoc", None) # stc.STC_LEX_ASCIIDOC |
| 95 | + ] |
| 96 | + passed = failed = 0 |
| 97 | + for fname, content in ftests: |
| 98 | + got = detect(fname, content) |
| 99 | + ok = got == stc.STC_LEX_NULL |
| 100 | + status = "OK" if ok else "FAIL" |
| 101 | + if not ok: |
| 102 | + print(f" [{status}] detect({fname!r}) → {got!r}") |
| 103 | + failed += 1 |
| 104 | + else: |
| 105 | + passed += 1 |
| 106 | + |
| 107 | + print(f"\nResults: {passed} passed, {failed} failed out of {len(tests)} tests") |
| 108 | + assert failed == 0 |
| 109 | + |
| 110 | + def test_file_type_detections(self): |
| 111 | + result = detect_from_file(datafilereader.LIBRARY_WITH_SPACES_IN_PATH) |
| 112 | + assert result == stc.STC_LEX_PYTHON |
| 113 | + |
| 114 | + def test_invalid_file_type_detections(self): |
| 115 | + result = detect_from_file(datafilereader.RESOURCES_DIR + "/nonexisting.jason") |
| 116 | + assert result == stc.STC_LEX_NULL |
| 117 | + |
85 | 118 |
|
86 | 119 | if __name__ == '__main__': |
87 | 120 | unittest.main() |
0 commit comments