2014-08-28 13:47:58 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright 2014 by Sam Mikes. All rights reserved.
|
|
|
|
# This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import os
|
|
|
|
import yaml
|
2014-10-24 18:44:18 +02:00
|
|
|
import imp
|
2014-08-28 13:47:58 +02:00
|
|
|
|
|
|
|
# add parent dir to search path
|
|
|
|
import sys
|
2014-10-24 18:44:18 +02:00
|
|
|
#sys.path.insert(0, "..")
|
|
|
|
|
|
|
|
f = None
|
|
|
|
try:
|
2015-07-06 16:09:26 +02:00
|
|
|
(f, pathname, description) = imp.find_module("monkeyYaml", [os.path.join(os.getcwd(), "../")])
|
|
|
|
module = imp.load_module("monkeyYaml", f, pathname, description)
|
|
|
|
monkeyYaml = module
|
2014-10-24 18:44:18 +02:00
|
|
|
except:
|
2015-07-06 16:09:26 +02:00
|
|
|
raise ImportError("Cannot load monkeyYaml")
|
2014-10-24 18:44:18 +02:00
|
|
|
finally:
|
2015-07-06 16:09:26 +02:00
|
|
|
if f:
|
|
|
|
f.close()
|
2014-10-24 18:44:18 +02:00
|
|
|
|
|
|
|
#import monkeyYaml
|
2014-08-28 13:47:58 +02:00
|
|
|
|
|
|
|
class TestMonkeyYAMLParsing(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_empty(self):
|
|
|
|
self.assertEqual(monkeyYaml.load(""), yaml.load(""))
|
|
|
|
|
|
|
|
def test_newline(self):
|
|
|
|
self.assertEqual(monkeyYaml.load("\n"), yaml.load("\n"))
|
|
|
|
|
|
|
|
def test_oneline(self):
|
|
|
|
y = "foo: bar"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_twolines(self):
|
|
|
|
y = "foo: bar\nbaz_bletch : blith:er"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_multiLine(self):
|
|
|
|
y = "foo: >\n bar\nbaz: 3"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_es5id(self):
|
|
|
|
y = "es5id: 15.2.3.6-4-102"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_Multiline_1(self):
|
|
|
|
lines = [" foo"]
|
|
|
|
value = ">"
|
|
|
|
y = "\n".join([value] + lines)
|
|
|
|
(lines, value) = monkeyYaml.myMultiline(lines, value)
|
|
|
|
self.assertEqual(lines, [])
|
|
|
|
self.assertEqual(value, yaml.load(y))
|
|
|
|
|
2015-03-30 22:46:49 +02:00
|
|
|
def test_Multiline_2(self):
|
2014-08-28 13:47:58 +02:00
|
|
|
lines = [" foo", " bar"]
|
|
|
|
value = ">"
|
|
|
|
y = "\n".join([value] + lines)
|
|
|
|
(lines, value) = monkeyYaml.myMultiline(lines, value)
|
|
|
|
self.assertEqual(lines, [])
|
|
|
|
self.assertEqual(value, yaml.load(y))
|
|
|
|
|
2015-03-30 22:46:49 +02:00
|
|
|
def test_Multiline_3(self):
|
|
|
|
lines = [" foo", " bar"]
|
|
|
|
value = ">"
|
|
|
|
y = "\n".join([value] + lines)
|
|
|
|
(lines, value) = monkeyYaml.myMultiline(lines, value)
|
|
|
|
self.assertEqual(lines, [])
|
|
|
|
self.assertEqual(value, yaml.load(y))
|
|
|
|
|
|
|
|
def test_Multiline_4(self):
|
|
|
|
lines = [" foo", " bar", " other: 42"]
|
|
|
|
value = ">"
|
|
|
|
(lines, value) = monkeyYaml.myMultiline(lines, value)
|
|
|
|
self.assertEqual(lines, [" other: 42"])
|
|
|
|
self.assertEqual(value, "foo bar")
|
|
|
|
|
2014-08-28 13:47:58 +02:00
|
|
|
def test_myLeading(self):
|
|
|
|
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" foo"))
|
|
|
|
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" "))
|
|
|
|
self.assertEqual(0, monkeyYaml.myLeadingSpaces("\t "))
|
|
|
|
|
|
|
|
def test_includes_flow(self):
|
|
|
|
y = "includes: [a.js,b.js, c_with_wings.js]\n"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_myFlowList_1(self):
|
|
|
|
y = "[a.js,b.js, c_with_wings.js, 3, 4.12]"
|
|
|
|
self.assertEqual(monkeyYaml.myFlowList(y), ['a.js', 'b.js', 'c_with_wings.js', 3, 4.12])
|
|
|
|
|
|
|
|
def test_multiline_list_1(self):
|
|
|
|
y = "foo:\n - bar\n - baz"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
2015-03-30 22:46:49 +02:00
|
|
|
def test_multiline_list2(self):
|
2014-08-28 13:47:58 +02:00
|
|
|
self.assertEqual(monkeyYaml.myRemoveListHeader(2, " - foo"), "foo")
|
|
|
|
|
2015-03-30 22:46:49 +02:00
|
|
|
def test_multiline_list3(self):
|
2014-08-28 13:47:58 +02:00
|
|
|
(lines, value) = monkeyYaml.myMultilineList([" - foo", " - bar", "baz: bletch"], "")
|
|
|
|
self.assertEqual(lines, ["baz: bletch"])
|
|
|
|
self.assertEqual(value, ["foo", "bar"])
|
|
|
|
|
2015-06-10 16:30:55 +02:00
|
|
|
def test_multiline_list_carriage_return(self):
|
|
|
|
y = "foo:\r\n - bar\r\n - baz"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
2015-03-30 22:46:49 +02:00
|
|
|
def test_oneline_indented(self):
|
2015-07-01 16:19:33 +02:00
|
|
|
y = " foo: bar\n baz: baf\n"
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
2015-03-30 22:46:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_indentation_215(self):
|
2015-07-01 16:19:33 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
2015-03-30 22:46:49 +02:00
|
|
|
description: >
|
|
|
|
The method should exist on the Array prototype, and it should be writable
|
|
|
|
and configurable, but not enumerable.
|
|
|
|
includes: [propertyHelper.js]
|
|
|
|
es6id: 22.1.3.13
|
|
|
|
"""
|
2015-07-01 16:19:33 +02:00
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
2015-03-30 22:46:49 +02:00
|
|
|
|
|
|
|
def test_indentation_215_2(self):
|
2015-07-01 16:19:33 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
2015-03-30 22:46:49 +02:00
|
|
|
description: >
|
|
|
|
The method should exist
|
|
|
|
includes: [propertyHelper.js]
|
|
|
|
es6id: 22.1.3.13
|
|
|
|
"""
|
2015-07-01 16:19:33 +02:00
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_line_folding(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
|
|
|
description: aaa
|
|
|
|
bbb
|
|
|
|
es6id: 19.1.2.1
|
|
|
|
"""
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_line_folding_2(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
|
|
|
description: ccc
|
|
|
|
|
|
|
|
ddd
|
|
|
|
|
|
|
|
es6id: 19.1.2.1
|
|
|
|
"""
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_line_folding_3(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
|
|
|
description: eee
|
|
|
|
|
|
|
|
|
|
|
|
fff
|
|
|
|
es6id: 19.1.2.1
|
|
|
|
"""
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
|
|
|
def test_line_folding_4(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
y = """
|
|
|
|
description: ggg
|
|
|
|
|
|
|
|
hhh
|
|
|
|
iii
|
|
|
|
|
|
|
|
jjj
|
|
|
|
es6id: 19.1.2.1
|
|
|
|
"""
|
|
|
|
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
|
|
|
|
|
2014-08-28 13:47:58 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|