Commit fb847cf0 authored by Roy Revelt's avatar Roy Revelt

test: split test file into separate files

parent 64cf4ed9
......@@ -36,6 +36,7 @@
"1.13.2": 74234.4811199878,
"1.13.3": 75125.85883610796,
"1.13.4": 60858.17448499726,
"lastPublished": 60858.17448499726,
"lastRan": 60858.17448499726
"1.13.7": 68500.09861386566,
"lastPublished": 68500.09861386566,
"lastRan": 68500.09861386566
}
\ No newline at end of file
import tap from "tap";
import compare from "../dist/ast-compare.esm";
// api tests
// -----------------------------------------------------------------------------
tap.test("01 - fourth argument doesn't break anything", (t) => {
t.same(
compare({ a: "1", b: "2" }, { a: "1", b: "2", c: "3" }, null, true),
false,
"01.01"
);
t.same(
compare({ a: "1", b: "2" }, { a: "1", b: "2", c: "3" }, null, false),
false,
"01.02"
);
t.end();
});
This diff is collapsed.
import tap from "tap";
import compare from "../dist/ast-compare.esm";
// matching empty arrays
// -----------------------------------------------------------------------------
tap.test("01 - matching empty arrays - blank vs. normal - defaults", (t) => {
t.same(compare({ a: "1", b: "2", c: 3 }, {}), false, "01");
t.end();
});
tap.test("02 - matching empty arrays - blank vs. empty - defaults", (t) => {
t.same(compare({ a: "\n\n", b: "\t", c: " " }, {}), false, "02");
t.end();
});
tap.test(
"03 - matching empty arrays - blank vs. normal - opts.hungryForWhitespace",
(t) => {
t.same(
compare({ a: "1", b: "2", c: 3 }, {}, { hungryForWhitespace: true }),
false,
"03"
);
t.end();
}
);
tap.test(
"04 - matching empty arrays - blank vs. empty - opts.hungryForWhitespace",
(t) => {
t.same(
compare(
{ a: "\n\n", b: "\t", c: " " },
{},
{ hungryForWhitespace: true }
),
true,
"04"
);
t.end();
}
);
tap.test(
"05 - matching empty arrays - blank vs. normal - opts.matchStrictly",
(t) => {
t.same(
compare({ a: "1", b: "2", c: 3 }, {}, { matchStrictly: true }),
false,
"05"
);
t.end();
}
);
tap.test(
"06 - matching empty arrays - blank vs. empty - opts.matchStrictly",
(t) => {
t.same(
compare({ a: "\n\n", b: "\t", c: " " }, {}, { matchStrictly: true }),
false,
"06"
);
t.end();
}
);
tap.test("07 - matching empty arrays - blank vs. normal - both opts", (t) => {
t.same(
compare(
{ a: "1", b: "2", c: 3 },
{},
{ hungryForWhitespace: true, matchStrictly: true }
),
false,
"07"
);
t.end();
});
tap.test("08 - matching empty arrays - blank vs. empty - both opts", (t) => {
t.same(
compare(
{ a: "\n\n", b: "\t", c: " " },
{},
{ hungryForWhitespace: true, matchStrictly: true }
),
true,
"08"
);
t.end();
});
import tap from "tap";
import compare from "../dist/ast-compare.esm";
// loose mode
// -----------------------------------------------------------------------------
tap.test("01 - hungryForWhitespace, empty strings within arrays", (t) => {
t.same(
compare(
{
type: "rule",
selectors: [" ", "\n\n\n", "\t\t\t \t\t\n\n"],
},
{
type: "rule",
selectors: [],
}
),
false,
"01.01"
);
t.same(
compare(
{
type: "rule",
selectors: [" ", "\n\n\n", "\t\t\t \t\t\n\n"],
},
{
type: "rule",
selectors: [],
},
{
hungryForWhitespace: true,
}
),
true,
"01.02"
);
t.same(
compare(
{
type: "rule",
selectors: [],
},
{
type: "rule",
selectors: [" ", "\n\n\n", "\t\t\t \t\t\n\n"],
}
),
false,
"01.03"
);
t.same(
compare(
{
type: "rule",
selectors: [],
},
{
type: "rule",
selectors: [" ", "\n\n\n", "\t\t\t \t\t\n\n"],
},
{
hungryForWhitespace: true,
}
),
true,
"01.04"
);
t.end();
});
import tap from "tap";
import compare from "../dist/ast-compare.esm";
// nested
// -----------------------------------------------------------------------------
tap.test("01 - simple nested plain objects", (t) => {
t.same(
compare({ a: { d: "4" }, b: "2", c: "3" }, { a: { d: "4" }, b: "2" }),
true,
"01"
);
t.end();
});
tap.test("02 - simple nested plain objects + array wrapper", (t) => {
t.same(
compare({ a: [{ d: "4" }], b: "2", c: "3" }, { a: [{ d: "4" }], b: "2" }),
true,
"02"
);
t.end();
});
tap.test("03 - simple nested plain objects, won't find", (t) => {
t.same(
compare({ a: { d: "4" }, b: "2" }, { a: { d: "4" }, b: "2", c: "3" }),
false,
"03"
);
t.end();
});
tap.test(
"04 - simple nested plain objects + array wrapper, won't find",
(t) => {
t.same(
compare({ a: [{ d: "4" }], b: "2" }, { a: [{ d: "4" }], b: "2", c: "3" }),
false,
"04"
);
t.end();
}
);
tap.test("05 - obj, multiple nested levels, bigObj has more", (t) => {
t.same(
compare(
{ a: { b: { c: { d: [{ e: "1" }, { f: "2" }] } } } },
{ a: { b: { c: { d: [{ e: "1" }] } } } }
),
true,
"05"
);
t.end();
});
tap.test("06 - obj, multiple nested levels, equal", (t) => {
t.same(
compare(
{ a: { b: { c: { d: [{ e: "1" }, { f: "2" }] } } } },
{ a: { b: { c: { d: [{ e: "1" }, { f: "2" }] } } } }
),
true,
"06"
);
t.end();
});
tap.test("07 - obj, multiple nested levels, smallObj has more", (t) => {
t.same(
compare(
{ a: { b: { c: { d: [{ e: "1" }] } } } },
{ a: { b: { c: { d: [{ e: "1" }, { f: "2" }] } } } }
),
false,
"07"
);
t.end();
});
tap.test("08 - obj, deeper level doesn't match", (t) => {
t.same(compare({ a: { b: "c" } }, { a: { b: "d" } }), false, "08");
t.end();
});
tap.test("09 - empty string and empty nested object - defaults", (t) => {
t.same(
compare("", {
key2: [],
key3: [""],
}),
false,
"09"
);
t.end();
});
tap.test(
"10 - empty string and empty nested object - hungryForWhitespace",
(t) => {
t.same(
compare(
"",
{
key2: [],
key3: [""],
},
{
hungryForWhitespace: true,
}
),
true,
"10"
);
t.end();
}
);
tap.test("11 - empty string and empty nested object - matchStrictly", (t) => {
t.same(
compare(
"",
{
key2: [],
key3: [""],
},
{
matchStrictly: true,
}
),
false,
"11"
);
t.end();
});
tap.test(
"12 - empty string and empty nested object - hungryForWhitespace + matchStrictly",
(t) => {
t.same(
compare(
"",
{
key2: [],
key3: [""],
},
{
hungryForWhitespace: true,
matchStrictly: true,
}
),
false,
"12"
);
t.end();
}
);
tap.test(
"13 - empty string and empty nested object - hungryForWhitespace + matchStrictly",
(t) => {
t.same(
compare(
"",
{},
{
hungryForWhitespace: true,
matchStrictly: true,
}
),
true,
"13"
);
t.end();
}
);
tap.test("14 - multiple keys", (t) => {
t.same(
compare(
{
key2: "\n\n \t \n \n ",
key3: "val3",
key4: "val4",
},
{
key2: [],
key3: [],
}
),
false,
"14"
);
t.end();
});
tap.test("15 - multiple keys", (t) => {
t.same(
compare(
{
key2: "\n\n \t \n \n ",
key3: "val3",
key4: "val4",
},
{
key2: [],
key3: [],
},
{
hungryForWhitespace: true,
}
),
false,
"15"
);
t.end();
});
This diff is collapsed.
import tap from "tap";
import compare from "../dist/ast-compare.esm";
// strings
// -----------------------------------------------------------------------------
tap.test("01 - simple strings", (t) => {
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nbbbbb", {
matchStrictly: false,
hungryForWhitespace: false,
}),
true,
"01.01"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nc", {
matchStrictly: false,
hungryForWhitespace: false,
}),
false,
"01.02"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nbbbbb", {
matchStrictly: false,
hungryForWhitespace: true,
}),
true,
"01.03"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nc", {
matchStrictly: false,
hungryForWhitespace: true,
}),
false,
"01.04"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nbbbbb", {
matchStrictly: true,
hungryForWhitespace: false,
}),
true,
"01.05"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nc", {
matchStrictly: true,
hungryForWhitespace: false,
}),
false,
"01.06"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nbbbbb", {
matchStrictly: true,
hungryForWhitespace: true,
}),
true,
"01.07"
);
t.same(
compare("aaaaa\nbbbbb", "aaaaa\nc", {
matchStrictly: true,
hungryForWhitespace: true,
}),
false,
"01.08"
);
t.end();
});
tap.test("02 - strings compared and fails", (t) => {
t.same(compare("aaaaa\nbbbbb", ["aaaaa\nbbbbb"]), false, "02.01");
t.not(
compare("aaaaa\nbbbbb", ["aaaaa\nbbbbb"], { verboseWhenMismatches: true }),
true,
"05.02.02"
);
t.end();
});
tap.test("03 - strings in arrays compared, positive", (t) => {
t.same(compare(["aaaaa\nbbbbb"], ["aaaaa\nbbbbb"]), true, "03");
t.end();
});
tap.test(
"04 - string against empty array or empty string within an array",
(t) => {
t.same(compare(["aaaaa\nbbbbb"], []), false, "04.01");
t.same(
compare(["aaaaa\nbbbbb"], [], { hungryForWhitespace: true }),
true,
"04.02"
);
t.same(
compare(["aaaaa\nbbbbb"], ["\n\n\n"], { hungryForWhitespace: true }),
true,
"04.03"
);
t.same(
compare(["aaaaa\nbbbbb", "\t\t\t \n\n\n", " "], ["\n\n\n"], {
hungryForWhitespace: true,
}),
true,
"04.04"
);
t.end();
}
);
tap.test("05 - string vs empty space", (t) => {
t.same(
compare("aaaaa\nbbbbb", "\n\n\n \t\t\t ", {
matchStrictly: false,
hungryForWhitespace: false,
}),
false,
"05.01"
);
t.same(
compare("aaaaa\nbbbbb", "\n\n\n \t\t\t ", {
matchStrictly: false,
hungryForWhitespace: true,
}),
false,
"05.02"
);
t.same(
compare("aaaaa\nbbbbb", "\n\n\n \t\t\t ", {
matchStrictly: true,
hungryForWhitespace: false,
}),
false,
"05.03"
);
t.same(
compare("aaaaa\nbbbbb", "\n\n\n \t\t\t ", {
matchStrictly: true,
hungryForWhitespace: true,
}),
false,
"05.04"
);
t.end();
});
tap.test("06 - empty space vs different empty space", (t) => {
t.same(
compare(" \n\n\n\n\n\n\n\n ", "\n\n\n \t\t\t ", {
matchStrictly: false,
hungryForWhitespace: false,
}),
false,
"06.01"
);
t.same(
compare(" \n\n\n\n\n\n\n\n ", "\n\n\n \t\t\t ", {
matchStrictly: false,
hungryForWhitespace: true,
}),
true,
"06.02"
);
t.same(
compare(" \n\n\n\n\n\n\n\n ", "\n\n\n \t\t\t ", {
matchStrictly: true,
hungryForWhitespace: false,
}),
false,
"06.03"
);
t.same(
compare(" \n\n\n\n\n\n\n\n ", "\n\n\n \t\t\t ", {
matchStrictly: true,
hungryForWhitespace: true,
}),
true,
"06.04"
);
t.end();
});
tap.test("07 - two arrays, one empty", (t) => {
t.same(
compare(["\t\t\t\t\t\t \n\n\n \t\t\t"], []),
false,
"07.01 - in root, defaults"
);
t.same(
compare(
{ a: ["\t\t\t\t\t\t \n\n\n \t\t\t"] },
{ a: [] },
{ hungryForWhitespace: true }
),
true,
"07.02 - in root, defaults"
);
t.same(
compare([], ["\t\t\t\t\t\t \n\n\n \t\t\t"], {
hungryForWhitespace: true,
}),
true,
"07.03 - in root, defaults, opposite from #2"
);
t.end();
});
tap.test("08 - opts.matchStrictly", (t) => {
t.same(
compare(
{ a: "a" },
{},
{ matchStrictly: true, verboseWhenMismatches: true }
),
false,
"08.01 - key count mismatch"
);
t.same(
typeof compare(
{},
{ a: "a" },
{ matchStrictly: true, verboseWhenMismatches: true }
),
"string",
"08.02 - key count mismatch"
);
t.end();
});
This diff is collapsed.