aboutsummaryrefslogtreecommitdiffstats
path: root/tests/indent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/indent')
-rw-r--r--tests/indent/ecma/binary_expression.js4
-rw-r--r--tests/indent/ecma/callback.js6
-rw-r--r--tests/indent/ecma/func.js37
-rw-r--r--tests/indent/ecma/object.js5
-rw-r--r--tests/indent/ecma/ternary.js6
-rw-r--r--tests/indent/ecma/variable.js6
-rw-r--r--tests/indent/javascript_spec.lua59
7 files changed, 118 insertions, 5 deletions
diff --git a/tests/indent/ecma/binary_expression.js b/tests/indent/ecma/binary_expression.js
new file mode 100644
index 000000000..132fee9cf
--- /dev/null
+++ b/tests/indent/ecma/binary_expression.js
@@ -0,0 +1,4 @@
+if_this_is_correct &&
+ run_this_thing()
+ .filter()
+ .map()
diff --git a/tests/indent/ecma/callback.js b/tests/indent/ecma/callback.js
new file mode 100644
index 000000000..a4e1e533e
--- /dev/null
+++ b/tests/indent/ecma/callback.js
@@ -0,0 +1,6 @@
+const itemById = Array.from(
+ new Set()
+).reduce((byId, item) => {
+ byId[item.id] = item
+ return result;
+}, {})
diff --git a/tests/indent/ecma/func.js b/tests/indent/ecma/func.js
new file mode 100644
index 000000000..5bbfa1e31
--- /dev/null
+++ b/tests/indent/ecma/func.js
@@ -0,0 +1,37 @@
+const arrow_func = (
+ a,
+ b,
+ c
+) => {
+ log(a, b, c)
+}
+
+const arrow_func_without_brace = (a, b, c) =>
+ log(
+ a,
+ b,
+ c
+ )
+
+function func_def(
+ a,
+ b,
+ { c = '' }
+) {
+ log(a, b, c)
+}
+
+func_call(
+ a,
+ (b) => b
+)
+
+chained_func_call()
+ .map()
+ .filter()
+
+func_call(
+ chained_func_call()
+ .map()
+ .filter()
+)
diff --git a/tests/indent/ecma/object.js b/tests/indent/ecma/object.js
new file mode 100644
index 000000000..ca09d238a
--- /dev/null
+++ b/tests/indent/ecma/object.js
@@ -0,0 +1,5 @@
+const obj = {
+ a: 1,
+ b: "2",
+ ["c"]: `three`
+}
diff --git a/tests/indent/ecma/ternary.js b/tests/indent/ecma/ternary.js
new file mode 100644
index 000000000..479e411c9
--- /dev/null
+++ b/tests/indent/ecma/ternary.js
@@ -0,0 +1,6 @@
+const value =
+ condition
+ ? typeof number === 'string'
+ ? Number(number)
+ : number
+ : null;
diff --git a/tests/indent/ecma/variable.js b/tests/indent/ecma/variable.js
new file mode 100644
index 000000000..80d34beea
--- /dev/null
+++ b/tests/indent/ecma/variable.js
@@ -0,0 +1,6 @@
+let a =
+ if_this_is_right() && then_this()
+
+a = func_call()
+ .map()
+ .filter()
diff --git a/tests/indent/javascript_spec.lua b/tests/indent/javascript_spec.lua
index 889e59fdb..022f26f67 100644
--- a/tests/indent/javascript_spec.lua
+++ b/tests/indent/javascript_spec.lua
@@ -19,14 +19,30 @@ describe("indent JavaScript:", function()
describe("new line:", function()
for _, info in ipairs {
{ 1, 2 },
- { 2, 2 },
- { 3, 2 },
+ { 2, 4 },
+ { 3, 4 },
+ } do
+ run:new_line("ecma/binary_expression.js", { on_line = info[1], text = "//", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
{ 4, 2 },
+ { 6, 0 },
+ } do
+ run:new_line("ecma/callback.js", { on_line = info[1], text = "//", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
+ { 2, 2 },
{ 5, 2 },
- { 6, 2 },
{ 7, 0 },
+ { 12, 4 },
+ { 18, 2 },
+ { 19, 2 },
+ { 20, 2 },
+ { 25, 2 },
} do
- run:new_line("ecma/try_catch.js", { on_line = info[1], text = "hello()", indent = info[2] })
+ run:new_line("ecma/func.js", { on_line = info[1], text = "//", indent = info[2] }, info[3], info[4])
end
for _, info in ipairs {
@@ -40,7 +56,40 @@ describe("indent JavaScript:", function()
{ 12, 2 },
{ 13, 0 },
} do
- run:new_line("ecma/if_else.js", { on_line = info[1], text = "hello()", indent = info[2] })
+ run:new_line("ecma/if_else.js", { on_line = info[1], text = "hello()", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
+ { 2, 2 },
+ { 5, 0 },
+ } do
+ run:new_line("ecma/object.js", { on_line = info[1], text = "//", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
+ { 3, 6 },
+ { 4, 6 },
+ } do
+ run:new_line("ecma/ternary.js", { on_line = info[1], text = "//", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
+ { 1, 2 },
+ { 2, 2 },
+ { 3, 2 },
+ { 4, 2 },
+ { 5, 2 },
+ { 6, 2 },
+ { 7, 0 },
+ } do
+ run:new_line("ecma/try_catch.js", { on_line = info[1], text = "hello()", indent = info[2] }, info[3], info[4])
+ end
+
+ for _, info in ipairs {
+ { 1, 2 },
+ { 2, 0 },
+ } do
+ run:new_line("ecma/variable.js", { on_line = info[1], text = "hello()", indent = info[2] }, info[3], info[4])
end
end)
end)