Skip to content

Commit

Permalink
test: split combination and scenario tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naiyerasif committed Apr 16, 2024
1 parent 07ea84b commit a8adb33
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 32 deletions.
14 changes: 14 additions & 0 deletions test/combination.test.js
@@ -0,0 +1,14 @@
import test from "ava";
import FenceParser from "../src/index.js";
import fixtures from "./fixtures/combinations.js";
import macro from "./macro.js";

const parser = new FenceParser();

for (const fixture of fixtures) {
const result = parser.parse(fixture.input);
const expected = fixture.output;
const title = `input "${fixture.input}"`;

test(title, macro, result, expected);
}
21 changes: 0 additions & 21 deletions test/fixtures.js → test/fixtures/combinations.js
Expand Up @@ -32,27 +32,6 @@ const prepareFixtures = (fixtures) => {
};

const fixtures = [
// edge cases
{
input: [''],
output: {},
},
{
input: ['{}'],
output: {},
},
{
input: ['true="false"'],
output: {
true: "false",
},
},
{
input: ['maxRun="1"'],
output: {
maxRun: "1",
},
},
// isolated
{
input: ['{1}'],
Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/scenarios.js
@@ -0,0 +1,33 @@
const fixtures = [
{
input: '',
output: {},
},
{
input: '{}',
output: {},
},
{
input: 'true="false"',
output: {
true: "false",
},
},
{
input: 'maxRun="1"',
output: {
maxRun: "1",
},
},
{
input: '{1}',
output: { mark: [1] },
options: { rangeKey: "mark" },
},
{
input: '{11..8, 20}',
output: { highlight: [8, 9, 10, 11, 20] },
}
];

export default fixtures;
12 changes: 1 addition & 11 deletions test/parser.test.js → test/macro.js
@@ -1,8 +1,4 @@
import test from "ava";
import FenceParser from "../src/index.js";
import fixtures from "./fixtures.js";

const parser = new FenceParser();

const macro = test.macro({
exec(t, input, expected) {
Expand All @@ -25,10 +21,4 @@ const macro = test.macro({
}
});

for (const fixture of fixtures) {
const result = parser.parse(fixture.input);
const expected = fixture.output;
const title = `input "${fixture.input}"`;

test(title, macro, result, expected);
}
export default macro;
20 changes: 20 additions & 0 deletions test/scenario.test.js
@@ -0,0 +1,20 @@
import test from "ava";
import FenceParser from "../src/index.js";
import fixtures from "./fixtures/scenarios.js";
import macro from "./macro.js";

const parser = new FenceParser();

for (const fixture of fixtures) {
let result;
if (fixture.options) {
result = (new FenceParser(fixture.options)).parse(fixture.input);
} else {
result = parser.parse(fixture.input);
}

const expected = fixture.output;
const title = `input "${fixture.input}"`;

test(title, macro, result, expected);
}

0 comments on commit a8adb33

Please sign in to comment.