// This file tests the parsing of extended-hints, double bracket sections {{ .. }}
// for all sorts of markdown.
describe('Markdown to xml extended hint dropdown', function() {
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
Translation between Dropdown and ________ is straightforward.
[[
(Multiple Choice) {{ Good Job::Yes, multiple choice is the right answer. }}
Text Input {{ No, text input problems don't present options. }}
Numerical Input {{ No, numerical input problems don't present options. }}
]]
Clowns have funny _________ to make people laugh.
[[
dogs {{ NOPE::Not dogs, not cats, not toads }}
(FACES) {{ With lots of makeup, doncha know?}}
money {{ Clowns don't have any money, of course }}
donkeys {{don't be an ass.}}
-no hint-
]]
\
`);
expect(data).toXMLEqual(`\
Translation between Dropdown and ________ is straightforward.
Clowns have funny _________ to make people laugh.
\
`);
});
it('produces xml with demand hint', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
Translation between Dropdown and ________ is straightforward.
[[
(Right) {{ Good Job::yes }}
Wrong 1 {{no}}
Wrong 2 {{ Label::no }}
]]
|| 0) zero ||
|| 1) one ||
|| 2) two ||\
`);
expect(data).toXMLEqual(`\
Translation between Dropdown and ________ is straightforward.
0) zero1) one2) two\
`);
});
it('produces xml with single-line markdown syntax', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
A Question ________ is answered.
[[(Right), Wrong 1, Wrong 2]]
|| 0) zero ||
|| 1) one ||\
`);
expect(data).toXMLEqual(`\
A Question ________ is answered.
0) zero1) one\
`);
});
it('produces xml with fewer newlines', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q1<<
[[ (aa) {{ hint1 }}
bb
cc {{ hint2 }} ]]\
`);
expect(data).toXMLEqual(`\
\
`);
});
it('produces xml even with lots of whitespace', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q1<<
[[
aa {{ hint1 }}
bb {{ hint2 }}
(cc)
]]\
`);
expect(data).toXMLEqual(`\
\
`);
});
});
describe('Markdown to xml extended hint checkbox', function() {
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Select all the fruits from the list<<
[x] Apple {{ selected: You're right that apple is a fruit. }, {unselected: Remember that apple is also a fruit.}}
[ ] Mushroom {{U: You're right that mushrooms aren't fruit}, { selected: Mushroom is a fungus, not a fruit.}}
[x] Grape {{ selected: You're right that grape is a fruit }, {unselected: Remember that grape is also a fruit.}}
[ ] Mustang
[ ] Camero {{S:I don't know what a Camero is but it isn't a fruit.},{U:What is a camero anyway?}}
{{ ((A*B)) You're right that apple is a fruit, but there's one you're missing. Also, mushroom is not a fruit.}}
{{ ((B*C)) You're right that grape is a fruit, but there's one you're missing. Also, mushroom is not a fruit. }}
>>Select all the vegetables from the list<<
[ ] Banana {{ selected: No, sorry, a banana is a fruit. }, {unselected: poor banana.}}
[ ] Ice Cream
[ ] Mushroom {{U: You're right that mushrooms aren't vegetables.}, { selected: Mushroom is a fungus, not a vegetable.}}
[x] Brussel Sprout {{S: Brussel sprouts are vegetables.}, {u: Brussel sprout is the only vegetable in this list.}}
{{ ((A*B)) Making a banana split? }}
{{ ((B*D)) That will make a horrible dessert: a brussel sprout split? }}\
`);
expect(data).toXMLEqual(`\
Apple
You're right that apple is a fruit.Remember that apple is also a fruit.Mushroom
Mushroom is a fungus, not a fruit.You're right that mushrooms aren't fruitGrape
You're right that grape is a fruitRemember that grape is also a fruit.MustangCamero
I don't know what a Camero is but it isn't a fruit.What is a camero anyway?You're right that apple is a fruit, but there's one you're missing. Also, mushroom is not a fruit.You're right that grape is a fruit, but there's one you're missing. Also, mushroom is not a fruit.Banana
No, sorry, a banana is a fruit.poor banana.Ice CreamMushroom
Mushroom is a fungus, not a vegetable.You're right that mushrooms aren't vegetables.Brussel Sprout
Brussel sprouts are vegetables.Brussel sprout is the only vegetable in this list.Making a banana split?That will make a horrible dessert: a brussel sprout split?\
`);
});
it('produces xml also with demand hints', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Select all the fruits from the list<<
[x] Apple {{ selected: You're right that apple is a fruit. }, {unselected: Remember that apple is also a fruit.}}
[ ] Mushroom {{U: You're right that mushrooms aren't fruit}, { selected: Mushroom is a fungus, not a fruit.}}
[x] Grape {{ selected: You're right that grape is a fruit }, {unselected: Remember that grape is also a fruit.}}
[ ] Mustang
[ ] Camero {{S:I don't know what a Camero is but it isn't a fruit.},{U:What is a camero anyway?}}
{{ ((A*B)) You're right that apple is a fruit, but there's one you're missing. Also, mushroom is not a fruit.}}
{{ ((B*C)) You're right that grape is a fruit, but there's one you're missing. Also, mushroom is not a fruit.}}
>>Select all the vegetables from the list<<
[ ] Banana {{ selected: No, sorry, a banana is a fruit. }, {unselected: poor banana.}}
[ ] Ice Cream
[ ] Mushroom {{U: You're right that mushrooms aren't vegatbles}, { selected: Mushroom is a fungus, not a vegetable.}}
[x] Brussel Sprout {{S: Brussel sprouts are vegetables.}, {u: Brussel sprout is the only vegetable in this list.}}
{{ ((A*B)) Making a banana split? }}
{{ ((B*D)) That will make a horrible dessert: a brussel sprout split? }}
|| Hint one.||
|| Hint two. ||
|| Hint three. ||\
`);
expect(data).toXMLEqual(`\
Apple
You're right that apple is a fruit.Remember that apple is also a fruit.Mushroom
Mushroom is a fungus, not a fruit.You're right that mushrooms aren't fruitGrape
You're right that grape is a fruitRemember that grape is also a fruit.MustangCamero
I don't know what a Camero is but it isn't a fruit.What is a camero anyway?You're right that apple is a fruit, but there's one you're missing. Also, mushroom is not a fruit.You're right that grape is a fruit, but there's one you're missing. Also, mushroom is not a fruit.Banana
No, sorry, a banana is a fruit.poor banana.Ice CreamMushroom
Mushroom is a fungus, not a vegetable.You're right that mushrooms aren't vegatblesBrussel Sprout
Brussel sprouts are vegetables.Brussel sprout is the only vegetable in this list.Making a banana split?That will make a horrible dessert: a brussel sprout split?Hint one.Hint two.Hint three.\
`);
});
});
describe('Markdown to xml extended hint multiple choice', function() {
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Select the fruit from the list<<
() Mushroom {{ Mushroom is a fungus, not a fruit.}}
() Potato
(x) Apple {{ OUTSTANDING::Apple is indeed a fruit.}}
>>Select the vegetables from the list<<
() Mushroom {{ Mushroom is a fungus, not a vegetable.}}
(x) Potato {{ Potato is a root vegetable. }}
() Apple {{ OOPS::Apple is a fruit.}}\
`);
expect(data).toXMLEqual(`\
Mushroom
Mushroom is a fungus, not a fruit.PotatoApple
Apple is indeed a fruit.Mushroom
Mushroom is a fungus, not a vegetable.Potato
Potato is a root vegetable.Apple
Apple is a fruit.\
`);
});
it('produces xml with demand hints', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Select the fruit from the list<<
() Mushroom {{ Mushroom is a fungus, not a fruit.}}
() Potato
(x) Apple {{ OUTSTANDING::Apple is indeed a fruit.}}
|| 0) spaces on previous line. ||
|| 1) roses are red. ||
>>Select the vegetables from the list<<
() Mushroom {{ Mushroom is a fungus, not a vegetable.}}
(x) Potato {{ Potato is a root vegetable. }}
() Apple {{ OOPS::Apple is a fruit.}}
|| 2) where are the lions? ||
\
`);
expect(data).toXMLEqual(`\
Mushroom
Mushroom is a fungus, not a fruit.PotatoApple
Apple is indeed a fruit.Mushroom
Mushroom is a fungus, not a vegetable.Potato
Potato is a root vegetable.Apple
Apple is a fruit.0) spaces on previous line.1) roses are red.2) where are the lions?\
`);
});
});
describe('Markdown to xml extended hint text input', function() {
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>In which country would you find the city of Paris?<<
= France {{ BRAVO::Viva la France! }}
\
`);
expect(data).toXMLEqual(`\
Viva la France!\
`);
});
it('produces xml with or=', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>Where Paris?<<
= France {{ BRAVO::hint1}}
or= USA {{ meh::hint2 }}
\
`);
expect(data).toXMLEqual(`\
hint1hint2\
`);
});
it('produces xml with not=', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>Revenge is a dish best served<<
= cold {{khaaaaaan!}}
not= warm {{feedback2}}
\
`);
expect(data).toXMLEqual(`\
khaaaaaan!feedback2\
`);
});
it('produces xml with s=', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>q<<
s= 2 {{feedback1}}
\
`);
expect(data).toXMLEqual(`\
feedback1\
`);
});
it('produces xml with = and or= and not=', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>q<<
= aaa
or= bbb {{feedback1}}
not= no {{feedback2}}
or= ccc
\
`);
expect(data).toXMLEqual(`\
feedback1feedback2\
`);
});
it('produces xml with s= and or=', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>q<<
s= 2 {{feedback1}}
or= bbb {{feedback2}}
or= ccc
\
`);
expect(data).toXMLEqual(`\
feedback1feedback2\
`);
});
it('produces xml with each = making a new question', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q<<
= aaa
or= bbb
s= ccc\
`);
expect(data).toXMLEqual(`\
\
`);
});
it('produces xml with each = making a new question amid blank lines and paragraphs', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
paragraph
>>q<<
= aaa
or= bbb
s= ccc
paragraph 2
\
`);
expect(data).toXMLEqual(`\
paragraph
paragraph 2
\
`);
});
it('produces xml without a question when or= is just hung out there by itself', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
paragraph
>>q<<
or= aaa
paragraph 2
\
`);
expect(data).toXMLEqual(`\
paragraph
or= aaa
paragraph 2
\
`);
});
it('produces xml with each = with feedback making a new question', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q<<
s= aaa
or= bbb {{feedback1}}
= ccc {{feedback2}}
\
`);
expect(data).toXMLEqual(`\
feedback1feedback2\
`);
});
it('produces xml with demand hints', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`>>Where Paris?<<
= France {{ BRAVO::hint1 }}
|| There are actually two countries with cities named Paris. ||
|| Paris is the capital of one of those countries. ||
\
`);
expect(data).toXMLEqual(`\
hint1There are actually two countries with cities named Paris.Paris is the capital of one of those countries.`);
});
});
describe('Markdown to xml extended hint numeric input', function() {
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Enter the numerical value of Pi:<<
= 3.14159 +- .02 {{ Pie for everyone! }}
>>Enter the approximate value of 502*9:<<
= 4518 +- 15% {{PIE:: No pie for you!}}
>>Enter the number of fingers on a human hand<<
= 5
\
`);
expect(data).toXMLEqual(`\
Pie for everyone!No pie for you!\
`);
});
// The output xml here shows some of the quirks of how historical markdown parsing does or does not put
// in blank lines.
it('numeric input with hints and demand hints', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>text1<<
= 1 {{ hint1 }}
|| hintA ||
>>text2<<
= 2 {{ hint2 }}
|| hintB ||
\
`);
expect(data).toXMLEqual(`\
hint1hint2hintAhintB\
`);
});
});
describe('Markdown to xml extended hint with multiline hints', () =>
it('produces xml', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>Checkboxes<<
[x] A {{
selected: aaa },
{unselected:bbb}}
[ ] B {{U: c}, {
selected: d.}}
{{ ((A*B)) A*B hint}}
>>What is 1 + 1?<<
= 2 {{ part one, and
part two
}}
>>hello?<<
= hello {{
hello
hint
}}
>>multiple choice<<
(x) AA{{hint1}}
() BB {{
hint2
}}
( ) CC {{ hint3
}}
>>dropdown<<
[[
W1 {{
no }}
W2 {{
nope}}
(C1) {{ yes
}}
]]
|| aaa ||
||bbb||
|| ccc ||
\
`);
expect(data).toXMLEqual(`\
A
aaabbbB
d.cA*B hintpart one, and part twohello hintAA
hint1BB
hint2CC
hint3aaabbbccc\
`);
})
);
describe('Markdown to xml extended hint with tricky syntax cases', function() {
it('produces xml with unicode', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>á and Ø<<
(x) Ø{{Ø}}
() BB
|| Ø ||
\
`);
expect(data).toXMLEqual(`\
Ø
ØBBØ\
`);
});
it('produces xml with quote-type characters', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>"quotes" aren't \`fun\`<<
() "hello" {{ isn't }}
(x) "isn't" {{ "hello" }}
\
`);
expect(data).toXMLEqual(`\
"hello"
isn't"isn't"
"hello"\
`);
});
it('produces xml with almost but not quite multiple choice syntax', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q1<<
this (x)
() a {{ (hint) }}
(x) b
that (y)\
`);
expect(data).toXMLEqual(`\
this (x)
a (hint)b
that (y)
\
`);
});
// An incomplete checkbox hint passes through to cue the author
it('produce xml with almost but not quite checkboxgroup syntax', function() {
const data = MarkdownEditingDescriptor.markdownToXml(`\
>>q1<<
this [x]
[ ] a [square]
[x] b {{ this hint passes through }}
that []\
`);
expect(data).toXMLEqual(`\
this [x]
a [square]b {{ this hint passes through }}
that []
\
`);
});
// It's sort of a pain to edit DOS line endings without some editor or other "fixing" them
// for you. Therefore, we construct DOS line endings on the fly just for the test.
it('produces xml with DOS \r\n line endings', function() {
let markdown = `\
>>q22<<
[[
(x) {{ hintx
these
span
}}
yy {{ meh::hinty }}
zzz {{ hintz }}
]]\
`;
markdown = markdown.replace(/\n/g, '\r\n'); // make DOS line endings
const data = MarkdownEditingDescriptor.markdownToXml(markdown);
expect(data).toXMLEqual(`\
\
`);
});
});