From 791f400004d1f2503e1e462968c448c4a9d3ef3c 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 & code review. --- components/prism-tap.js | 18 ++++---- components/prism-tap.min.js | 2 +- tests/languages/tap/bail_out_feature.test | 13 ++++++ tests/languages/tap/directive_feature.test | 15 +++++++ tests/languages/tap/pass_fail_feature.test | 17 ++++++++ tests/languages/tap/plan_feature.test | 13 ++++++ tests/languages/tap/pragma_feature.test | 13 ++++++ tests/languages/tap/version_feature.test | 11 +++++ tests/languages/tap/yamlish_feature.test | 50 ++++++++++++++++++++++ 9 files changed, 142 insertions(+), 10 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/pass_fail_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..80e5d3eb78 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\r]*/, + pass: /ok[^#{\n\r]*/, + pragma: /pragma [+-][a-z]+/, + bailout: /bail out!.*/i, + version: /TAP version \d+/i, + plan: /\d+\.\.\d+(?: +#.*)?/, 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/components/prism-tap.min.js b/components/prism-tap.min.js index c5631482f1..4f14d9bd2a 100644 --- a/components/prism-tap.min.js +++ b/components/prism-tap.min.js @@ -1 +1 @@ -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,subtest:{pattern:/(^|\n)( )*# Subtest(?:: (.*))?(\n|$)/,greedy:!0},punctuation:/[{}]/,comment:/#.*/,yamlish:{pattern:/(^|\n)(( )*( ))---\n(.*?\n)+\2\.\.\.(\n|$)/,lookbehind:!0,inside:Prism.languages.yaml,alias:"language-yaml"}}; \ No newline at end of file +Prism.languages.tap={fail:/not ok[^#{\n\r]*/,pass:/ok[^#{\n\r]*/,pragma:/pragma [+-][a-z]+/,bailout:/bail out!.*/i,version:/TAP version \d+/i,plan:/\d+\.\.\d+(?: +#.*)?/,subtest:{pattern:/# Subtest(?:: .*)?/,greedy:!0},punctuation:/[{}]/,directive:/#.*/,yamlish:{pattern:/(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m,lookbehind:!0,inside:Prism.languages.yaml,alias:"language-yaml"}}; \ No newline at end of file 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/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/plan_feature.test b/tests/languages/tap/plan_feature.test new file mode 100644 index 0000000000..8bdcd4e7a6 --- /dev/null +++ b/tests/languages/tap/plan_feature.test @@ -0,0 +1,13 @@ +1..10 +1..10 # directive + +---------------------------------------------------- + +[ + ["plan", "1..10" ], + ["plan", "1..10 # directive" ] +] + +---------------------------------------------------- + +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