From 59047db8c98be8003c5cbf2c001f19945bca9399 Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Sun, 27 May 2018 17:46:52 -0400 Subject: [PATCH] Add tests Also fix up the patterns in light of said tests. --- components/prism-tap.js | 18 ++++---- tests/languages/tap/bail_out_feature.test | 13 ++++++ tests/languages/tap/directive_feature.test | 15 +++++++ tests/languages/tap/fail_feature.test | 13 ++++++ tests/languages/tap/pass_fail_feature.test | 17 ++++++++ tests/languages/tap/pass_feature.test | 13 ++++++ tests/languages/tap/plan_feature.test | 11 +++++ tests/languages/tap/pragma_feature.test | 13 ++++++ tests/languages/tap/version_feature.test | 11 +++++ tests/languages/tap/yamlish_feature.test | 50 ++++++++++++++++++++++ 10 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 tests/languages/tap/bail_out_feature.test create mode 100644 tests/languages/tap/directive_feature.test create mode 100644 tests/languages/tap/fail_feature.test create mode 100644 tests/languages/tap/pass_fail_feature.test create mode 100644 tests/languages/tap/pass_feature.test create mode 100644 tests/languages/tap/plan_feature.test create mode 100644 tests/languages/tap/pragma_feature.test create mode 100644 tests/languages/tap/version_feature.test create mode 100644 tests/languages/tap/yamlish_feature.test diff --git a/components/prism-tap.js b/components/prism-tap.js index 97bef158e2..b7b3fb9990 100644 --- a/components/prism-tap.js +++ b/components/prism-tap.js @@ -1,18 +1,18 @@ Prism.languages.tap = { - pass: /(^|\n)( )*ok[^#\{\n]*/, - fail: /(^|\n)( )*not ok[^#\{\n]*/, - pragma: /(^|\n)( )*pragma ([+-])([a-z]+)(\n|$)/, - bailout: /(^|\n)( )*bail out!(.*)(\n|$)/i, - version: /(^|\n)( )*TAP version ([0-9]+)(\n|$)/i, - plan: /(^|\n)( )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?(\n|$)/m, + fail: /( )*not ok[^#\{\n]*/, + pass: /( )*ok[^#\{\n]*/, + pragma: /( )*pragma ([\+-])([a-z]+)/, + bailout: /( )*bail out!(.*)/i, + version: /( )*TAP version ([0-9]+)/i, + plan: /( )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?/m, subtest: { - pattern: /(^|\n)( )*# Subtest(?:: (.*))?(\n|$)/, + pattern: /( )*# Subtest(?:: (.*))?/, greedy: true }, punctuation: /[{}]/, - 'comment': /#.*/, + directive: /#.*/, yamlish: { - pattern: /(^|\n)(( )*( ))---\n(.*?\n)+\2\.\.\.(\n|$)/, + pattern: /(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m, lookbehind: true, inside: Prism.languages.yaml, alias: 'language-yaml' diff --git a/tests/languages/tap/bail_out_feature.test b/tests/languages/tap/bail_out_feature.test new file mode 100644 index 0000000000..eba81647c4 --- /dev/null +++ b/tests/languages/tap/bail_out_feature.test @@ -0,0 +1,13 @@ +Bail out! Couldn't connect to database. +bail out! Failed to call API. + +---------------------------------------------------- + +[ + ["bailout", "Bail out! Couldn't connect to database."], + ["bailout", "bail out! Failed to call API."] +] + +---------------------------------------------------- + +Checks bail out diff --git a/tests/languages/tap/directive_feature.test b/tests/languages/tap/directive_feature.test new file mode 100644 index 0000000000..5a3ff9105d --- /dev/null +++ b/tests/languages/tap/directive_feature.test @@ -0,0 +1,15 @@ +ok # SKIP test not written +ok 42 this is the description # TODO write test + +---------------------------------------------------- + +[ + ["pass", "ok " ], + ["directive", "# SKIP test not written"], + ["pass", "ok 42 this is the description "], + ["directive", "# TODO write test"] +] + +---------------------------------------------------- + +Checks directives diff --git a/tests/languages/tap/fail_feature.test b/tests/languages/tap/fail_feature.test new file mode 100644 index 0000000000..039a5bb851 --- /dev/null +++ b/tests/languages/tap/fail_feature.test @@ -0,0 +1,13 @@ +not ok +not ok 42 this is the description of the test + +---------------------------------------------------- + +[ + ["fail", "not ok" ], + ["fail", "not ok 42 this is the description of the test"] +] + +---------------------------------------------------- + +Checks test fails diff --git a/tests/languages/tap/pass_fail_feature.test b/tests/languages/tap/pass_fail_feature.test new file mode 100644 index 0000000000..d0782990a3 --- /dev/null +++ b/tests/languages/tap/pass_fail_feature.test @@ -0,0 +1,17 @@ +not ok +not ok 42 this is the description of the test +ok +ok 42 this is the description of the test + +---------------------------------------------------- + +[ + ["fail", "not ok" ], + ["fail", "not ok 42 this is the description of the test"], + ["pass", "ok" ], + ["pass", "ok 42 this is the description of the test"] +] + +---------------------------------------------------- + +Checks test pass & fail together correctly diff --git a/tests/languages/tap/pass_feature.test b/tests/languages/tap/pass_feature.test new file mode 100644 index 0000000000..7075160870 --- /dev/null +++ b/tests/languages/tap/pass_feature.test @@ -0,0 +1,13 @@ +ok +ok 42 this is the description of the test + +---------------------------------------------------- + +[ + ["pass", "ok" ], + ["pass", "ok 42 this is the description of the test"] +] + +---------------------------------------------------- + +Checks test pass diff --git a/tests/languages/tap/plan_feature.test b/tests/languages/tap/plan_feature.test new file mode 100644 index 0000000000..ec628c90f7 --- /dev/null +++ b/tests/languages/tap/plan_feature.test @@ -0,0 +1,11 @@ +1..10 + +---------------------------------------------------- + +[ + ["plan", "1..10" ] +] + +---------------------------------------------------- + +Checks TAP plan diff --git a/tests/languages/tap/pragma_feature.test b/tests/languages/tap/pragma_feature.test new file mode 100644 index 0000000000..7775f2e535 --- /dev/null +++ b/tests/languages/tap/pragma_feature.test @@ -0,0 +1,13 @@ +pragma +strict +pragma -strict + +---------------------------------------------------- + +[ + ["pragma", "pragma +strict"], + ["pragma", "pragma -strict"] +] + +---------------------------------------------------- + +Checks pragma diff --git a/tests/languages/tap/version_feature.test b/tests/languages/tap/version_feature.test new file mode 100644 index 0000000000..600bcccc3b --- /dev/null +++ b/tests/languages/tap/version_feature.test @@ -0,0 +1,11 @@ +TAP version 13 + +---------------------------------------------------- + +[ + ["version", "TAP version 13" ] +] + +---------------------------------------------------- + +Checks TAP version diff --git a/tests/languages/tap/yamlish_feature.test b/tests/languages/tap/yamlish_feature.test new file mode 100644 index 0000000000..be4a19e3d8 --- /dev/null +++ b/tests/languages/tap/yamlish_feature.test @@ -0,0 +1,50 @@ +ok + --- + message: "Failed with error 'hostname peebles.example.com not found'" + severity: fail + data: + got: + hostname: 'peebles.example.com' + address: ~ + expected: + hostname: 'peebles.example.com' + address: '85.193.201.85' + ... + +---------------------------------------------------- + +[ + ["pass", "ok"], + ["yamlish", [ + ["punctuation", "---"], + ["key", "message"], + ["punctuation", ":"], + ["string", "\"Failed with error 'hostname peebles.example.com not found'\""], + ["key", "severity"], + ["punctuation", ":"], + " fail\n ", + ["key", "data"], + ["punctuation", ":"], + ["key", "got"], + ["punctuation", ":"], + ["key", "hostname"], + ["punctuation", ":"], + ["string", "'peebles.example.com'"], + ["key", "address"], + ["punctuation", ":"], + ["null", "~"], + ["key", "expected"], + ["punctuation", ":"], + ["key", "hostname"], + ["punctuation", ":"], + ["string", "'peebles.example.com'"], + ["key", "address"], + ["punctuation", ":"], + ["string", "'85.193.201.85'"], + ["punctuation", "..."] + ]] +] + +---------------------------------------------------- + +Checks yaml embedding