Repository navigation
Expand file tree
/
Copy pathmarkdown-language-preprocessor.test.js
More file actions
53 lines (48 loc) · 2.37 KB
/
Copy pathmarkdown-language-preprocessor.test.js
File metadata and controls
53 lines (48 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const assert = require('node:assert/strict');
const { getLanguage } = require('../language-registry.js');
const {
firstLessonUrl,
homeUrl,
lessonUrl,
resolveLanguage,
siteRootUrl
} = require('../language-navigation.js');
const { preprocessLanguageDirectives } = require('../markdown-language-preprocessor.js');
const preprocess = (markdown, languageId) =>
preprocessLanguageDirectives(markdown, languageId, getLanguage);
assert.equal(
preprocess('Shared\n:::language dotnet\n.NET only\n:::\n:::language python\nPython only\n:::\nEnd', 'dotnet'),
'Shared\n.NET only\nEnd'
);
assert.equal(
preprocess('Shared\n:::language dotnet\n.NET only\n:::\n:::language python\nPython only\n:::\nEnd', 'python'),
'Shared\nPython only\nEnd'
);
assert.throws(
() => preprocess(':::language dotnet\n:::language python\n:::\n:::', 'dotnet'),
/cannot be nested/
);
assert.throws(() => preprocess(':::language unknown\n:::', 'dotnet'), /unknown language/);
assert.throws(() => preprocess(':::language dotnet\nUnclosed', 'dotnet'), /not closed/);
assert.throws(() => preprocess(':::', 'dotnet'), /closing directive has no open/);
assert.throws(() => preprocess(':::unexpected', 'dotnet'), /expected :::language/);
assert.equal(lessonUrl('04-mcp-safety', 'rust'), '?step=04-mcp-safety&lang=rust');
assert.equal(lessonUrl('04-mcp-safety'), '?step=04-mcp-safety');
assert.equal(firstLessonUrl('java'), 'workshop/step.html?step=00-preflight&lang=java');
assert.equal(firstLessonUrl('python', 'museum'), 'workshop/step.html?step=museum-00-preflight&lang=python');
assert.equal(homeUrl('python'), '../index.html?lang=python');
assert.equal(homeUrl('python', 'museum'), '../index.html?lang=python&workshop=museum');
assert.equal(homeUrl(), '../index.html');
assert.equal(
siteRootUrl('https://expert-adventure-l67eo16.pages.github.io/workshop/step.html?step=00-preflight').href,
'https://expert-adventure-l67eo16.pages.github.io/'
);
assert.equal(
siteRootUrl('https://github.github.io/copilot-sdk-workshop/workshop/step.html').href,
'https://github.github.io/copilot-sdk-workshop/'
);
assert.equal(resolveLanguage('?lang=go', 'rust', getLanguage).id, 'go');
assert.equal(resolveLanguage('', 'rust', getLanguage).id, 'rust');
assert.equal(resolveLanguage('?lang=unknown', 'rust', getLanguage), null);
console.log('Workshop language directive and navigation tests passed.');