From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../test/xpcshell/test_attribute-parsing-01.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 devtools/client/shared/test/xpcshell/test_attribute-parsing-01.js (limited to 'devtools/client/shared/test/xpcshell/test_attribute-parsing-01.js') diff --git a/devtools/client/shared/test/xpcshell/test_attribute-parsing-01.js b/devtools/client/shared/test/xpcshell/test_attribute-parsing-01.js new file mode 100644 index 0000000000..f3c0c159cd --- /dev/null +++ b/devtools/client/shared/test/xpcshell/test_attribute-parsing-01.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test splitBy from node-attribute-parser.js + +const { + splitBy, +} = require("resource://devtools/client/shared/node-attribute-parser.js"); + +const TEST_DATA = [ + { + value: "this is a test", + splitChar: " ", + expected: [ + { value: "this" }, + { value: " ", type: "string" }, + { value: "is" }, + { value: " ", type: "string" }, + { value: "a" }, + { value: " ", type: "string" }, + { value: "test" }, + ], + }, + { + value: "/path/to/handler", + splitChar: " ", + expected: [{ value: "/path/to/handler" }], + }, + { + value: "test", + splitChar: " ", + expected: [{ value: "test" }], + }, + { + value: " test ", + splitChar: " ", + expected: [ + { value: " ", type: "string" }, + { value: "test" }, + { value: " ", type: "string" }, + ], + }, + { + value: "", + splitChar: " ", + expected: [], + }, + { + value: " ", + splitChar: " ", + expected: [ + { value: " ", type: "string" }, + { value: " ", type: "string" }, + { value: " ", type: "string" }, + ], + }, +]; + +function run_test() { + for (const { value, splitChar, expected } of TEST_DATA) { + info("Splitting string: " + value); + const tokens = splitBy(value, splitChar); + + info("Checking that the number of parsed tokens is correct"); + Assert.equal(tokens.length, expected.length); + + for (let i = 0; i < tokens.length; i++) { + info("Checking the data in token " + i); + Assert.equal(tokens[i].value, expected[i].value); + if (expected[i].type) { + Assert.equal(tokens[i].type, expected[i].type); + } + } + } +} -- cgit v1.2.3