summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/fmt_tests.rs18
-rw-r--r--tests/specs/compile/include_data_files/__test__.jsonc41
-rw-r--r--tests/specs/compile/include_data_files/data-file.txt1
-rw-r--r--tests/specs/compile/include_data_files/main.js1
-rw-r--r--tests/specs/compile/include_data_files/non_existent.out6
-rw-r--r--tests/specs/compile/include_data_files/output.out1
-rw-r--r--tests/specs/doc/lint_html_success/lint_success_html.out2
-rw-r--r--tests/specs/fmt/sql/__test__.jsonc25
-rw-r--r--tests/specs/fmt/sql/badly_formatted.sql1
-rw-r--r--tests/specs/fmt/sql/ignore_file.sql3
-rw-r--r--tests/specs/fmt/sql/ignore_file2.sql3
-rw-r--r--tests/specs/fmt/sql/ignore_file3.sql6
-rw-r--r--tests/specs/fmt/sql/ignore_file4.sql3
-rw-r--r--tests/specs/fmt/sql/well_formatted.sql4
-rw-r--r--tests/specs/fmt/sql/wrong_file_ignore.sql6
-rw-r--r--tests/testdata/fmt/badly_formatted.md12
-rw-r--r--tests/testdata/fmt/badly_formatted.sql21
-rw-r--r--tests/testdata/fmt/badly_formatted_fixed.md15
-rw-r--r--tests/testdata/fmt/badly_formatted_fixed.sql22
19 files changed, 188 insertions, 3 deletions
diff --git a/tests/integration/fmt_tests.rs b/tests/integration/fmt_tests.rs
index b890b3b72..ccf54a4d0 100644
--- a/tests/integration/fmt_tests.rs
+++ b/tests/integration/fmt_tests.rs
@@ -61,6 +61,12 @@ fn fmt_test() {
let badly_formatted_yaml = t.path().join("badly_formatted.yaml");
badly_formatted_original_yaml.copy(&badly_formatted_yaml);
+ let fixed_sql = testdata_fmt_dir.join("badly_formatted_fixed.sql");
+ let badly_formatted_original_sql =
+ testdata_fmt_dir.join("badly_formatted.sql");
+ let badly_formatted_sql = t.path().join("badly_formatted.sql");
+ badly_formatted_original_sql.copy(&badly_formatted_sql);
+
// First, check formatting by ignoring the badly formatted file.
let output = context
.new_command()
@@ -71,11 +77,12 @@ fn fmt_test() {
"--unstable-html".to_string(),
"--unstable-component".to_string(),
"--unstable-yaml".to_string(),
+ "--unstable-sql".to_string(),
format!(
- "--ignore={badly_formatted_js},{badly_formatted_md},{badly_formatted_json},{badly_formatted_css},{badly_formatted_html},{badly_formatted_component},{badly_formatted_yaml},{badly_formatted_ipynb}",
+ "--ignore={badly_formatted_js},{badly_formatted_md},{badly_formatted_json},{badly_formatted_css},{badly_formatted_html},{badly_formatted_component},{badly_formatted_yaml},{badly_formatted_ipynb},{badly_formatted_sql}",
),
format!(
- "--check {badly_formatted_js} {badly_formatted_md} {badly_formatted_json} {badly_formatted_css} {badly_formatted_html} {badly_formatted_component} {badly_formatted_yaml} {badly_formatted_ipynb}",
+ "--check {badly_formatted_js} {badly_formatted_md} {badly_formatted_json} {badly_formatted_css} {badly_formatted_html} {badly_formatted_component} {badly_formatted_yaml} {badly_formatted_ipynb} {badly_formatted_sql}",
),
])
.run();
@@ -95,6 +102,7 @@ fn fmt_test() {
"--unstable-html".to_string(),
"--unstable-component".to_string(),
"--unstable-yaml".to_string(),
+ "--unstable-sql".to_string(),
badly_formatted_js.to_string(),
badly_formatted_md.to_string(),
badly_formatted_json.to_string(),
@@ -103,6 +111,7 @@ fn fmt_test() {
badly_formatted_component.to_string(),
badly_formatted_yaml.to_string(),
badly_formatted_ipynb.to_string(),
+ badly_formatted_sql.to_string(),
])
.run();
@@ -119,6 +128,7 @@ fn fmt_test() {
"--unstable-html".to_string(),
"--unstable-component".to_string(),
"--unstable-yaml".to_string(),
+ "--unstable-sql".to_string(),
badly_formatted_js.to_string(),
badly_formatted_md.to_string(),
badly_formatted_json.to_string(),
@@ -127,6 +137,7 @@ fn fmt_test() {
badly_formatted_component.to_string(),
badly_formatted_yaml.to_string(),
badly_formatted_ipynb.to_string(),
+ badly_formatted_sql.to_string(),
])
.run();
@@ -141,6 +152,7 @@ fn fmt_test() {
let expected_component = fixed_component.read_to_string();
let expected_yaml = fixed_yaml.read_to_string();
let expected_ipynb = fixed_ipynb.read_to_string();
+ let expected_sql = fixed_sql.read_to_string();
let actual_js = badly_formatted_js.read_to_string();
let actual_md = badly_formatted_md.read_to_string();
let actual_json = badly_formatted_json.read_to_string();
@@ -149,6 +161,7 @@ fn fmt_test() {
let actual_component = badly_formatted_component.read_to_string();
let actual_yaml = badly_formatted_yaml.read_to_string();
let actual_ipynb = badly_formatted_ipynb.read_to_string();
+ let actual_sql = badly_formatted_sql.read_to_string();
assert_eq!(expected_js, actual_js);
assert_eq!(expected_md, actual_md);
assert_eq!(expected_json, actual_json);
@@ -157,6 +170,7 @@ fn fmt_test() {
assert_eq!(expected_component, actual_component);
assert_eq!(expected_yaml, actual_yaml);
assert_eq!(expected_ipynb, actual_ipynb);
+ assert_eq!(expected_sql, actual_sql);
}
#[test]
diff --git a/tests/specs/compile/include_data_files/__test__.jsonc b/tests/specs/compile/include_data_files/__test__.jsonc
new file mode 100644
index 000000000..5d5d967ca
--- /dev/null
+++ b/tests/specs/compile/include_data_files/__test__.jsonc
@@ -0,0 +1,41 @@
+{
+ "tempDir": true,
+ "tests": {
+ "success": {
+ "steps": [{
+ "if": "unix",
+ "args": "compile --allow-read=data-file.txt --include data-file.txt --output main main.js",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "unix",
+ "commandName": "./main",
+ "args": [],
+ "output": "output.out",
+ "exitCode": 0
+ }, {
+ "if": "windows",
+ "args": "compile --allow-read=data-file.txt --include data-file.txt --output main.exe main.js",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "windows",
+ "commandName": "./main.exe",
+ "args": [],
+ "output": "output.out",
+ "exitCode": 0
+ }]
+ },
+ "non_existent": {
+ "steps": [{
+ "if": "unix",
+ "args": "compile --include does_not_exist.txt --output main main.js",
+ "output": "non_existent.out",
+ "exitCode": 1
+ }, {
+ "if": "windows",
+ "args": "compile --include does_not_exist.txt --output main.exe main.js",
+ "output": "non_existent.out",
+ "exitCode": 1
+ }]
+ }
+ }
+}
diff --git a/tests/specs/compile/include_data_files/data-file.txt b/tests/specs/compile/include_data_files/data-file.txt
new file mode 100644
index 000000000..b14df6442
--- /dev/null
+++ b/tests/specs/compile/include_data_files/data-file.txt
@@ -0,0 +1 @@
+Hi
diff --git a/tests/specs/compile/include_data_files/main.js b/tests/specs/compile/include_data_files/main.js
new file mode 100644
index 000000000..4c1f1e98d
--- /dev/null
+++ b/tests/specs/compile/include_data_files/main.js
@@ -0,0 +1 @@
+console.log(Deno.readTextFileSync("./data-file.txt").trim());
diff --git a/tests/specs/compile/include_data_files/non_existent.out b/tests/specs/compile/include_data_files/non_existent.out
new file mode 100644
index 000000000..a88b441ba
--- /dev/null
+++ b/tests/specs/compile/include_data_files/non_existent.out
@@ -0,0 +1,6 @@
+Compile file:///[WILDLINE]/main.js to [WILDLINE]
+error: Writing deno compile executable to temporary file 'main[WILDLINE]'
+
+Caused by:
+ 0: Including [WILDLINE]does_not_exist.txt
+ 1: [WILDLINE]
diff --git a/tests/specs/compile/include_data_files/output.out b/tests/specs/compile/include_data_files/output.out
new file mode 100644
index 000000000..b14df6442
--- /dev/null
+++ b/tests/specs/compile/include_data_files/output.out
@@ -0,0 +1 @@
+Hi
diff --git a/tests/specs/doc/lint_html_success/lint_success_html.out b/tests/specs/doc/lint_html_success/lint_success_html.out
index 783dd5927..57b179e22 100644
--- a/tests/specs/doc/lint_html_success/lint_success_html.out
+++ b/tests/specs/doc/lint_html_success/lint_success_html.out
@@ -1 +1 @@
-Written 12 files to "./docs/"
+Written 15 files to "./docs/"
diff --git a/tests/specs/fmt/sql/__test__.jsonc b/tests/specs/fmt/sql/__test__.jsonc
new file mode 100644
index 000000000..a335e79c2
--- /dev/null
+++ b/tests/specs/fmt/sql/__test__.jsonc
@@ -0,0 +1,25 @@
+{
+ "tempDir": true,
+ "tests": {
+ "nothing": {
+ "args": "fmt",
+ "output": "Checked 7 files\n"
+ },
+ "flag": {
+ "args": "fmt --unstable-sql",
+ "output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
+ },
+ "config_file": {
+ "steps": [{
+ "args": [
+ "eval",
+ "Deno.writeTextFile('deno.json', '{\\n \"unstable\": [\"fmt-sql\"]\\n}\\n')"
+ ],
+ "output": "[WILDCARD]"
+ }, {
+ "args": "fmt",
+ "output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
+ }]
+ }
+ }
+}
diff --git a/tests/specs/fmt/sql/badly_formatted.sql b/tests/specs/fmt/sql/badly_formatted.sql
new file mode 100644
index 000000000..619fc7afd
--- /dev/null
+++ b/tests/specs/fmt/sql/badly_formatted.sql
@@ -0,0 +1 @@
+select *; \ No newline at end of file
diff --git a/tests/specs/fmt/sql/ignore_file.sql b/tests/specs/fmt/sql/ignore_file.sql
new file mode 100644
index 000000000..62418c611
--- /dev/null
+++ b/tests/specs/fmt/sql/ignore_file.sql
@@ -0,0 +1,3 @@
+-- deno-fmt-ignore-file
+
+foo%!
diff --git a/tests/specs/fmt/sql/ignore_file2.sql b/tests/specs/fmt/sql/ignore_file2.sql
new file mode 100644
index 000000000..fe9969f1d
--- /dev/null
+++ b/tests/specs/fmt/sql/ignore_file2.sql
@@ -0,0 +1,3 @@
+--deno-fmt-ignore-file
+
+foo%!
diff --git a/tests/specs/fmt/sql/ignore_file3.sql b/tests/specs/fmt/sql/ignore_file3.sql
new file mode 100644
index 000000000..c87da3e59
--- /dev/null
+++ b/tests/specs/fmt/sql/ignore_file3.sql
@@ -0,0 +1,6 @@
+-- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+-- incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+-- quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+-- deno-fmt-ignore-file
+
+ foo%!
diff --git a/tests/specs/fmt/sql/ignore_file4.sql b/tests/specs/fmt/sql/ignore_file4.sql
new file mode 100644
index 000000000..2de65712a
--- /dev/null
+++ b/tests/specs/fmt/sql/ignore_file4.sql
@@ -0,0 +1,3 @@
+-- deno-fmt-ignore-file Foo bar biz
+
+ foo%!
diff --git a/tests/specs/fmt/sql/well_formatted.sql b/tests/specs/fmt/sql/well_formatted.sql
new file mode 100644
index 000000000..92ce98018
--- /dev/null
+++ b/tests/specs/fmt/sql/well_formatted.sql
@@ -0,0 +1,4 @@
+SELECT
+ *
+FROM
+ foo;
diff --git a/tests/specs/fmt/sql/wrong_file_ignore.sql b/tests/specs/fmt/sql/wrong_file_ignore.sql
new file mode 100644
index 000000000..c124855dc
--- /dev/null
+++ b/tests/specs/fmt/sql/wrong_file_ignore.sql
@@ -0,0 +1,6 @@
+-- File ignore directive only works if it's in the first cluster
+-- of comment, ie. there are no empty lines after the first n-leading lines.
+
+-- deno-fmt-ignore-file
+
+ foo \ No newline at end of file
diff --git a/tests/testdata/fmt/badly_formatted.md b/tests/testdata/fmt/badly_formatted.md
index 642918cea..be90ff845 100644
--- a/tests/testdata/fmt/badly_formatted.md
+++ b/tests/testdata/fmt/badly_formatted.md
@@ -63,3 +63,15 @@ function foo(): number {
let a:number
</script>
```
+
+
+```sql
+ seLect * , biz, buz
+from baz;
+```
+
+```sql
+-- deno-fmt-ignore-file
+ seLect * , biz, buz
+from baz;
+```
diff --git a/tests/testdata/fmt/badly_formatted.sql b/tests/testdata/fmt/badly_formatted.sql
new file mode 100644
index 000000000..8b4cb978f
--- /dev/null
+++ b/tests/testdata/fmt/badly_formatted.sql
@@ -0,0 +1,21 @@
+select * from foo;
+update foo set a = 'b'Where id = 'biz';
+
+
+ create table foo(id text not null
+bar text,
+ biz int,
+ buz number NOT NULL
+);
+
+INSERT
+ into
+ user_data
+ (first_name,
+last_name, address, phone, email)
+VALUES
+ ('foo', 'bar',
+ 'biz', 1, 'bix');
+
+
+
diff --git a/tests/testdata/fmt/badly_formatted_fixed.md b/tests/testdata/fmt/badly_formatted_fixed.md
index 21176742b..7a482e058 100644
--- a/tests/testdata/fmt/badly_formatted_fixed.md
+++ b/tests/testdata/fmt/badly_formatted_fixed.md
@@ -56,3 +56,18 @@ function foo(): number {
let a: number;
</script>
```
+
+```sql
+SELECT
+ *,
+ biz,
+ buz
+FROM
+ baz;
+```
+
+```sql
+-- deno-fmt-ignore-file
+ seLect * , biz, buz
+from baz;
+```
diff --git a/tests/testdata/fmt/badly_formatted_fixed.sql b/tests/testdata/fmt/badly_formatted_fixed.sql
new file mode 100644
index 000000000..d50c61921
--- /dev/null
+++ b/tests/testdata/fmt/badly_formatted_fixed.sql
@@ -0,0 +1,22 @@
+SELECT
+ *
+FROM
+ foo;
+
+UPDATE
+ foo
+SET
+ a = 'b'
+WHERE
+ id = 'biz';
+
+CREATE TABLE foo(
+ id text NOT NULL bar text,
+ biz int,
+ buz number NOT NULL
+);
+
+INSERT INTO
+ user_data (first_name, last_name, address, phone, email)
+VALUES
+ ('foo', 'bar', 'biz', 1, 'bix');