diff options
Diffstat (limited to '')
| -rw-r--r-- | spec/outputs/test/format_spec.lua | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua new file mode 100644 index 0000000..b12fb04 --- /dev/null +++ b/spec/outputs/test/format_spec.lua | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | local files = { | ||
| 2 | "spec/inputs/macro_export.yue", | ||
| 3 | "spec/inputs/attrib.yue", | ||
| 4 | "spec/inputs/macro.yue", | ||
| 5 | "spec/inputs/using.yue", | ||
| 6 | "spec/inputs/whitespace.yue", | ||
| 7 | "spec/inputs/nil_coalescing.yue", | ||
| 8 | "spec/inputs/stub.yue", | ||
| 9 | "spec/inputs/pipe.yue", | ||
| 10 | "spec/inputs/teal_lang.yue", | ||
| 11 | "spec/inputs/string.yue", | ||
| 12 | "spec/inputs/local.yue", | ||
| 13 | "spec/inputs/tables.yue", | ||
| 14 | "spec/inputs/operators.yue", | ||
| 15 | "spec/inputs/lists.yue", | ||
| 16 | "spec/inputs/compile_doc.yue", | ||
| 17 | "spec/inputs/switch.yue", | ||
| 18 | "spec/inputs/multiline_chain.yue", | ||
| 19 | "spec/inputs/existential.yue", | ||
| 20 | "spec/inputs/export_default.yue", | ||
| 21 | "spec/inputs/assign.yue", | ||
| 22 | "spec/inputs/literals.yue", | ||
| 23 | "spec/inputs/luarocks_upload.yue", | ||
| 24 | "spec/inputs/ambiguous.yue", | ||
| 25 | "spec/inputs/bubbling.yue", | ||
| 26 | "spec/inputs/try_catch.yue", | ||
| 27 | "spec/inputs/funcs.yue", | ||
| 28 | "spec/inputs/do.yue", | ||
| 29 | "spec/inputs/with.yue", | ||
| 30 | "spec/inputs/export.yue", | ||
| 31 | "spec/inputs/macro_todo.yue", | ||
| 32 | "spec/inputs/backcall.yue", | ||
| 33 | "spec/inputs/cond.yue", | ||
| 34 | "spec/inputs/in_expression.yue", | ||
| 35 | "spec/inputs/comprehension.yue", | ||
| 36 | "spec/inputs/macro_teal.yue", | ||
| 37 | "spec/inputs/import.yue", | ||
| 38 | "spec/inputs/unless_else.yue", | ||
| 39 | "spec/inputs/destructure.yue", | ||
| 40 | "spec/inputs/return.yue", | ||
| 41 | "spec/inputs/loops.yue", | ||
| 42 | "spec/inputs/class.yue", | ||
| 43 | "spec/inputs/vararg.yue", | ||
| 44 | "spec/inputs/goto.yue", | ||
| 45 | "spec/inputs/metatable.yue", | ||
| 46 | "spec/inputs/syntax.yue", | ||
| 47 | "spec/inputs/global.yue", | ||
| 48 | "spec/inputs/plus.yue", | ||
| 49 | "spec/inputs/test/class_spec.yue", | ||
| 50 | "spec/inputs/test/table_spreading_spec.yue", | ||
| 51 | "spec/inputs/test/loops_spec.yue", | ||
| 52 | "spec/inputs/test/format_spec.yue", | ||
| 53 | "spec/inputs/unicode/macro_export.yue", | ||
| 54 | "spec/inputs/unicode/attrib.yue", | ||
| 55 | "spec/inputs/unicode/macro.yue", | ||
| 56 | "spec/inputs/unicode/using.yue", | ||
| 57 | "spec/inputs/unicode/whitespace.yue", | ||
| 58 | "spec/inputs/unicode/nil_coalescing.yue", | ||
| 59 | "spec/inputs/unicode/stub.yue", | ||
| 60 | "spec/inputs/unicode/pipe.yue", | ||
| 61 | "spec/inputs/unicode/string.yue", | ||
| 62 | "spec/inputs/unicode/local.yue", | ||
| 63 | "spec/inputs/unicode/tables.yue", | ||
| 64 | "spec/inputs/unicode/operators.yue", | ||
| 65 | "spec/inputs/unicode/lists.yue", | ||
| 66 | "spec/inputs/unicode/switch.yue", | ||
| 67 | "spec/inputs/unicode/multiline_chain.yue", | ||
| 68 | "spec/inputs/unicode/existential.yue", | ||
| 69 | "spec/inputs/unicode/export_default.yue", | ||
| 70 | "spec/inputs/unicode/assign.yue", | ||
| 71 | "spec/inputs/unicode/literals.yue", | ||
| 72 | "spec/inputs/unicode/ambiguous.yue", | ||
| 73 | "spec/inputs/unicode/bubbling.yue", | ||
| 74 | "spec/inputs/unicode/try_catch.yue", | ||
| 75 | "spec/inputs/unicode/funcs.yue", | ||
| 76 | "spec/inputs/unicode/do.yue", | ||
| 77 | "spec/inputs/unicode/with.yue", | ||
| 78 | "spec/inputs/unicode/export.yue", | ||
| 79 | "spec/inputs/unicode/macro_todo.yue", | ||
| 80 | "spec/inputs/unicode/backcall.yue", | ||
| 81 | "spec/inputs/unicode/cond.yue", | ||
| 82 | "spec/inputs/unicode/in_expression.yue", | ||
| 83 | "spec/inputs/unicode/comprehension.yue", | ||
| 84 | "spec/inputs/unicode/import.yue", | ||
| 85 | "spec/inputs/unicode/unless_else.yue", | ||
| 86 | "spec/inputs/unicode/destructure.yue", | ||
| 87 | "spec/inputs/unicode/return.yue", | ||
| 88 | "spec/inputs/unicode/loops.yue", | ||
| 89 | "spec/inputs/unicode/class.yue", | ||
| 90 | "spec/inputs/unicode/vararg.yue", | ||
| 91 | "spec/inputs/unicode/goto.yue", | ||
| 92 | "spec/inputs/unicode/metatable.yue", | ||
| 93 | "spec/inputs/unicode/syntax.yue", | ||
| 94 | "spec/inputs/unicode/global.yue", | ||
| 95 | "spec/inputs/unicode/plus.yue" | ||
| 96 | } | ||
| 97 | local yue = require("yue") | ||
| 98 | local rewriteLineCol | ||
| 99 | rewriteLineCol = function(item) | ||
| 100 | item[2] = 0 | ||
| 101 | item[3] = 0 | ||
| 102 | for i = 4, #item do | ||
| 103 | do | ||
| 104 | local _exp_0 = type(item[i]) | ||
| 105 | if "table" == _exp_0 then | ||
| 106 | if item[i][1] == "comment" then | ||
| 107 | table.remove(item, i) | ||
| 108 | rewriteLineCol(item) | ||
| 109 | return | ||
| 110 | end | ||
| 111 | rewriteLineCol(item[i]) | ||
| 112 | end | ||
| 113 | end | ||
| 114 | end | ||
| 115 | end | ||
| 116 | return describe("format", function() | ||
| 117 | for _index_0 = 1, #files do | ||
| 118 | local file = files[_index_0] | ||
| 119 | it(file, function() | ||
| 120 | local f = io.open(file) | ||
| 121 | local code = f:read("a*") | ||
| 122 | f:close() | ||
| 123 | local original_ast = yue.to_ast(code) | ||
| 124 | assert.is_not_nil(original_ast) | ||
| 125 | rewriteLineCol(original_ast) | ||
| 126 | local formated = yue.format(code) | ||
| 127 | local ast = yue.to_ast(formated) | ||
| 128 | assert.is_not_nil(ast) | ||
| 129 | rewriteLineCol(ast) | ||
| 130 | return assert.same(original_ast, ast) | ||
| 131 | end) | ||
| 132 | end | ||
| 133 | end) | ||
