From d33d132bf4a3c297460cc9c195e3ba224db14986 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Sun, 5 Feb 2017 01:08:44 +0300 Subject: [PATCH 1/2] php compatibility --- .gitignore | 2 + src/yaml/Parser.hx | 334 +++++++++++----------- src/yaml/type/YTimestamp.hx | 30 +- test/TestPhp.hx | 25 ++ test/TestSuite.hx | 24 +- test/munit_compat/massive/munit/Assert.hx | 25 ++ test/test.hxml | 27 ++ test/yaml/YamlTest.hx | 9 +- test/yaml/type/YBinaryTest.hx | 4 +- test/yaml/type/YBoolTest.hx | 18 +- test/yaml/type/YFloatTest.hx | 18 +- test/yaml/type/YIntTest.hx | 10 +- test/yaml/type/YMergeTest.hx | 6 +- test/yaml/type/YNullTest.hx | 10 +- test/yaml/type/YOmapTest.hx | 14 +- test/yaml/type/YPairsTest.hx | 16 +- test/yaml/type/YSetTest.hx | 12 +- test/yaml/type/YTimestampTest.hx | 20 +- 18 files changed, 358 insertions(+), 246 deletions(-) create mode 100644 test/TestPhp.hx create mode 100644 test/munit_compat/massive/munit/Assert.hx diff --git a/.gitignore b/.gitignore index 5379f74..422511d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /.idea/ /.haxelib +/.vscode +/test/dev.hxml \ No newline at end of file diff --git a/src/yaml/Parser.hx b/src/yaml/Parser.hx index f54aa3d..588ad00 100644 --- a/src/yaml/Parser.hx +++ b/src/yaml/Parser.hx @@ -21,12 +21,12 @@ class ParserOptions public var maps:Bool; /** - @param schema Defines the schema to use while parsing. Defaults to yaml.schema.DefaultSchema. + @param schema Defines the schema to use while parsing. Defaults to yaml.schema.DefaultSchema. */ public function new(?schema:Schema = null) { this.schema = (schema == null) ? new DefaultSchema() : schema; - + strict = false; resolve = true; validation = true; @@ -34,8 +34,8 @@ class ParserOptions } /** - Use yaml.util.ObjectMap as the key => value container. - + Use yaml.util.ObjectMap as the key => value container. + Allows for complex key values. */ public function useMaps():ParserOptions @@ -46,7 +46,7 @@ class ParserOptions /** Use Dynamic objects as the key => value container. - + All keys will become Strings. */ public function useObjects():ParserOptions @@ -57,7 +57,7 @@ class ParserOptions /** Defines the schema to use while parsing. - + See yaml.Schema */ public function setSchema(schema:Schema):ParserOptions @@ -88,13 +88,13 @@ class ParserOptions class Parser { /** - Utility method to create ParserOptions for configuring a Parser instance. + Utility method to create ParserOptions for configuring a Parser instance. */ public static function options():ParserOptions { return new ParserOptions(); } - + var schema:Schema; var resolve:Bool; var validate:Bool; @@ -137,7 +137,7 @@ class Parser options.schema = new SafeSchema(); return parse(input, options); } - + public function parse(input:String, options:ParserOptions):Dynamic { var result:Dynamic = null; @@ -145,11 +145,11 @@ class Parser var responder = function (data:Dynamic) { - if (!received) + if (!received) { result = data; received = true; - } + } else { throw new YamlException('expected a single document in the stream, but found more'); @@ -160,7 +160,7 @@ class Parser return result; } - + public function parseAll(input:String, output:Dynamic->Void, options:ParserOptions):Void { #if (neko || cpp) @@ -168,9 +168,9 @@ class Parser #else this.input = input; #end - + this.output = output; - + schema = options.schema; resolve = options.resolve; validate = options.validation; @@ -225,7 +225,7 @@ class Parser for (i in 0...args.length) args[i] = Utf8.encode(args[i]); #end - + var handle:String; var prefix:String; @@ -263,18 +263,18 @@ class Parser readDocument(); } } - - function generateError(message:String, ?info:PosInfos) + + function generateError(message:String, ?info:PosInfos) { return new YamlException(message, info); } - function throwError(message:String, ?info:PosInfos) + function throwError(message:String, ?info:PosInfos) { throw generateError(message, info); } - function throwWarning(message:String, ?info:PosInfos) + function throwWarning(message:String, ?info:PosInfos) { var error = generateError(message, info); @@ -289,11 +289,11 @@ class Parser { var _result:String; - if (start < end) + if (start < end) { _result = yaml.util.Utf8.substring(input, start, end); - if (checkJson && validate) + if (checkJson && validate) { for (pos in 0...Utf8.length(_result))//.length) { @@ -306,31 +306,31 @@ class Parser result += _result; } } - + // when create dynamic object graph function mergeObjectMappings(destination:Dynamic, source:Dynamic) { if (Type.typeof(source) != ValueType.TObject) { throwError('cannot merge mappings; the provided source object is unacceptable'); } - + for (key in Reflect.fields(source)) if (!Reflect.hasField(destination, key)) Reflect.setField(destination, key, Reflect.field(source, key)); } - + // when creating map based graph function mergeMappings(destination:AnyObjectMap, source:AnyObjectMap) { if (!Std.is(source, AnyObjectMap)) { throwError('cannot merge mappings; the provided source object is unacceptable'); } - + for (key in source.keys()) if (!destination.exists(key)) destination.set(key, source.get(key)); } - + function storeObjectMappingPair(_result:Dynamic, keyTag:String, keyNode:Dynamic, valueNode:Dynamic):Dynamic { @@ -366,7 +366,7 @@ class Parser if ('tag:yaml.org,2002:merge' == keyTag) { - if (Std.is(valueNode, Array)) + if (Std.is(valueNode, Array)) { var list:Array = cast valueNode; for (member in list) @@ -389,13 +389,13 @@ class Parser if (CHAR_LINE_FEED == character) { position += 1; - } + } else if (CHAR_CARRIAGE_RETURN == character) { if (CHAR_LINE_FEED == Utf8.charCodeAt(input, (position + 1))) { position += 2; - } + } else { position += 1; @@ -408,7 +408,7 @@ class Parser line += 1; lineStart = position; - + if (position < length) character = Utf8.charCodeAt(input, position); else @@ -421,12 +421,12 @@ class Parser while (position < length) { - while (CHAR_SPACE == character || CHAR_TAB == character) + while (CHAR_SPACE == character || CHAR_TAB == character) { character = Utf8.charCodeAt(input, ++position); } - if (allowComments && CHAR_SHARP == character) + if (allowComments && CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); @@ -448,8 +448,8 @@ class Parser { throwWarning('deficient indentation'); } - } - else + } + else { break; } @@ -460,17 +460,17 @@ class Parser function testDocumentSeparator() { - if (position == lineStart && + if (position == lineStart && (CHAR_MINUS == character || CHAR_DOT == character) && Utf8.charCodeAt(input, (position + 1)) == character && - Utf8.charCodeAt(input, (position + 2)) == character) + Utf8.charCodeAt(input, (position + 2)) == character) { var pos = position + 3; var char = Utf8.charCodeAt(input, pos); - if (pos >= length || CHAR_SPACE == char || CHAR_TAB == char || - CHAR_LINE_FEED == char || CHAR_CARRIAGE_RETURN == char) + if (pos >= length || CHAR_SPACE == char || CHAR_TAB == char || + CHAR_LINE_FEED == char || CHAR_CARRIAGE_RETURN == char) { return true; } @@ -479,7 +479,7 @@ class Parser return false; } - function writeFoldedLines(count:Int) + function writeFoldedLines(count:Int) { if (1 == count) { @@ -502,7 +502,7 @@ class Parser var captureStart:Int; var captureEnd:Int; var hasPendingContent; - + var _line:Int = 0; var _kind = kind; var _result = result; @@ -531,7 +531,7 @@ class Parser return false; } - if (CHAR_QUESTION == character || CHAR_MINUS == character) + if (CHAR_QUESTION == character || CHAR_MINUS == character) { following = Utf8.charCodeAt(input, position + 1); @@ -544,7 +544,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET == following || CHAR_RIGHT_SQUARE_BRACKET == following || CHAR_LEFT_CURLY_BRACKET == following || - CHAR_RIGHT_CURLY_BRACKET == following)) + CHAR_RIGHT_CURLY_BRACKET == following)) { return false; } @@ -557,7 +557,7 @@ class Parser while (position < length) { - if (CHAR_COLON == character) + if (CHAR_COLON == character) { following = Utf8.charCodeAt(input, position + 1); @@ -570,7 +570,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET == following || CHAR_RIGHT_SQUARE_BRACKET == following || CHAR_LEFT_CURLY_BRACKET == following || - CHAR_RIGHT_CURLY_BRACKET == following)) + CHAR_RIGHT_CURLY_BRACKET == following)) { break; } @@ -588,7 +588,7 @@ class Parser break; } - } + } else if ((position == lineStart && testDocumentSeparator()) || withinFlowCollection && (CHAR_COMMA == character || @@ -605,15 +605,15 @@ class Parser _line = line; var _lineStart = lineStart; var _lineIndent = lineIndent; - + skipSeparationSpace(false, -1); - if (lineIndent >= nodeIndent) + if (lineIndent >= nodeIndent) { hasPendingContent = true; continue; - } - else + } + else { position = captureEnd; line = _line; @@ -632,26 +632,26 @@ class Parser hasPendingContent = false; } - if (CHAR_SPACE != character && CHAR_TAB != character) + if (CHAR_SPACE != character && CHAR_TAB != character) { captureEnd = position + 1; } if (++position >= length) break; - + character = Utf8.charCodeAt(input, position); } captureSegment(captureStart, captureEnd, false); - if (result != null) + if (result != null) { #if sys result = Utf8.decode(result); // convert back into native encoding #end return true; - } + } else { kind = _kind; @@ -675,19 +675,19 @@ class Parser character = Utf8.charCodeAt(input, ++position); captureStart = captureEnd = position; - while (position < length) + while (position < length) { if (CHAR_SINGLE_QUOTE == character) { captureSegment(captureStart, position, true); character = Utf8.charCodeAt(input, ++position); - if (CHAR_SINGLE_QUOTE == character) + if (CHAR_SINGLE_QUOTE == character) { captureStart = captureEnd = position; character = Utf8.charCodeAt(input, ++position); - } - else + } + else { #if sys result = Utf8.decode(result); @@ -696,18 +696,18 @@ class Parser } } - else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { captureSegment(captureStart, captureEnd, true); writeFoldedLines(skipSeparationSpace(false, nodeIndent)); captureStart = captureEnd = position; character = Utf8.charCodeAt(input, position); - } - else if (position == lineStart && testDocumentSeparator()) + } + else if (position == lineStart && testDocumentSeparator()) { throwError('unexpected end of the document within a single quoted scalar'); - } - else + } + else { character = Utf8.charCodeAt(input, ++position); captureEnd = position; @@ -718,7 +718,7 @@ class Parser return false; } - function readDoubleQuotedScalar(nodeIndent:Int) + function readDoubleQuotedScalar(nodeIndent:Int) { var captureStart:Int; var captureEnd:Int; @@ -749,11 +749,11 @@ class Parser captureSegment(captureStart, position, true); character = Utf8.charCodeAt(input, ++position); - if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { skipSeparationSpace(false, nodeIndent); } - else if (SIMPLE_ESCAPE_SEQUENCES.exists(character)) + else if (SIMPLE_ESCAPE_SEQUENCES.exists(character)) { result += SIMPLE_ESCAPE_SEQUENCES.get(character); character = Utf8.charCodeAt(input, ++position); @@ -789,14 +789,14 @@ class Parser character = Utf8.charCodeAt(input, ++position); } - else + else { throwError('unknown escape sequence'); } captureStart = captureEnd = position; - } + } else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { captureSegment(captureStart, captureEnd, true); @@ -940,7 +940,7 @@ class Parser if (null == tag) tag = '?'; } - + if (null != anchor) { @@ -953,7 +953,7 @@ class Parser hasContent = allowBlockCollections && readBlockSequence(blockIndent); } } - + if (null != tag && '!' != tag) { var _result:Dynamic = null; @@ -969,7 +969,7 @@ class Parser // non-specific tag is only assigned to plain scalars. So, it isn't // needed to check for 'kind' conformity. var resolvedType = false; - + try { _result = type.resolve(result, usingMaps, false); @@ -982,7 +982,7 @@ class Parser resolvedType = true; } catch (e:ResolveTypeException) {} - + if (resolvedType) break; } } @@ -998,7 +998,7 @@ class Parser if (!t.loader.skip) { - + try { _result = t.resolve(result, usingMaps, true); @@ -1006,7 +1006,7 @@ class Parser if (Std.is(_result, String)) _result = Utf8.decode(_result); #end - + result = _result; } catch(e:ResolveTypeException) @@ -1020,7 +1020,7 @@ class Parser throwWarning('unknown tag !<' + tag + '>'); } } - + return (null != tag || null != anchor || hasContent); } @@ -1069,8 +1069,8 @@ class Parser kind = isMapping ? KIND_OBJECT : KIND_ARRAY; result = _result; return true; - } - else if (!readNext) + } + else if (!readNext) { throwError('missed comma between flow collection entries'); } @@ -1085,7 +1085,7 @@ class Parser if (CHAR_SPACE == following || CHAR_TAB == following || CHAR_LINE_FEED == following || - CHAR_CARRIAGE_RETURN == following) + CHAR_CARRIAGE_RETURN == following) { isPair = isExplicitPair = true; position += 1; @@ -1107,7 +1107,7 @@ class Parser composeNode(nodeIndent, CONTEXT_FLOW_IN, false, true); valueNode = result; } - + if (isMapping) { if (usingMaps) @@ -1115,14 +1115,14 @@ class Parser else storeObjectMappingPair(_result, keyTag, keyNode, valueNode); } - else if (isPair) + else if (isPair) { if (usingMaps) _result.push(storeMappingPair(null, keyTag, keyNode, valueNode)); else _result.push(storeObjectMappingPair(null, keyTag, keyNode, valueNode)); } - else + else { _result.push(keyNode); } @@ -1133,7 +1133,7 @@ class Parser { readNext = true; character = Utf8.charCodeAt(input, ++position); - } + } else { readNext = false; @@ -1144,7 +1144,7 @@ class Parser return false; } - function readBlockScalar(nodeIndent:Int) + function readBlockScalar(nodeIndent:Int) { var captureStart:Int; var folding:Bool; @@ -1153,7 +1153,7 @@ class Parser var textIndent = nodeIndent; var emptyLines = -1; - switch (character) + switch (character) { case CHAR_VERTICAL_LINE: folding = false; @@ -1168,17 +1168,17 @@ class Parser kind = KIND_STRING; result = ''; - while (position < length) + while (position < length) { character = Utf8.charCodeAt(input, ++position); - if (CHAR_PLUS == character || CHAR_MINUS == character) + if (CHAR_PLUS == character || CHAR_MINUS == character) { - if (CHOMPING_CLIP == chomping) + if (CHOMPING_CLIP == chomping) { chomping = (CHAR_PLUS == character) ? CHOMPING_KEEP : CHOMPING_STRIP; } - else + else { throwError('repeat of a chomping mode identifier'); } @@ -1200,7 +1200,7 @@ class Parser throwError('repeat of an indentation width identifier'); } } - else + else { break; } @@ -1211,19 +1211,19 @@ class Parser do { character = Utf8.charCodeAt(input, ++position); } while (CHAR_SPACE == character || CHAR_TAB == character); - if (CHAR_SHARP == character) + if (CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); } } - while (position < length) + while (position < length) { readLineBreak(); lineIndent = 0; - while ((!detectedIndent || lineIndent < textIndent) && (CHAR_SPACE == character)) + while ((!detectedIndent || lineIndent < textIndent) && (CHAR_SPACE == character)) { lineIndent += 1; character = Utf8.charCodeAt(input, ++position); @@ -1234,24 +1234,24 @@ class Parser textIndent = lineIndent; } - if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { emptyLines += 1; continue; } // End of the scalar. Perform the chomping. - if (lineIndent < textIndent) + if (lineIndent < textIndent) { - if (CHOMPING_KEEP == chomping) + if (CHOMPING_KEEP == chomping) { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); #else result += Strings.repeat('\n', emptyLines + 1); #end - } - else if (CHOMPING_CLIP == chomping) + } + else if (CHOMPING_CLIP == chomping) { result += '\n'; } @@ -1260,9 +1260,9 @@ class Parser detectedIndent = true; - if (folding) + if (folding) { - if (CHAR_SPACE == character || CHAR_TAB == character) + if (CHAR_SPACE == character || CHAR_TAB == character) { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); @@ -1271,17 +1271,17 @@ class Parser #end emptyLines = 1; } - else if (0 == emptyLines) + else if (0 == emptyLines) { #if sys result += Utf8.encode(' '); #else result += ' '; #end - + emptyLines = 0; - } - else + } + else { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines)); @@ -1290,8 +1290,8 @@ class Parser #end emptyLines = 0; } - } - else + } + else { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); @@ -1308,7 +1308,7 @@ class Parser captureSegment(captureStart, position, false); } - + #if sys result = Utf8.decode(result); #end @@ -1316,7 +1316,7 @@ class Parser return true; } - function readBlockSequence(nodeIndent:Int) + function readBlockSequence(nodeIndent:Int) { var _line:Int; var _tag = tag; @@ -1327,7 +1327,7 @@ class Parser if (null != anchor) anchorMap.set(anchor, _result); - while (position < length) + while (position < length) { if (CHAR_MINUS != character) break; @@ -1337,7 +1337,7 @@ class Parser if (CHAR_SPACE != following && CHAR_TAB != following && CHAR_LINE_FEED != following && - CHAR_CARRIAGE_RETURN != following) + CHAR_CARRIAGE_RETURN != following) { break; } @@ -1346,9 +1346,9 @@ class Parser position += 1; character = following; - if (skipSeparationSpace(true, -1) != 0) + if (skipSeparationSpace(true, -1) != 0) { - if (lineIndent <= nodeIndent) + if (lineIndent <= nodeIndent) { _result.push(null); continue; @@ -1360,24 +1360,24 @@ class Parser _result.push(result); skipSeparationSpace(true, -1); - if ((line == _line || lineIndent > nodeIndent) && position < length) + if ((line == _line || lineIndent > nodeIndent) && position < length) { throwError('bad indentation of a sequence entry'); } - else if (lineIndent < nodeIndent) + else if (lineIndent < nodeIndent) { break; } } - if (detected) + if (detected) { tag = _tag; kind = KIND_ARRAY; result = _result; return true; - } - else + } + else { return false; } @@ -1390,7 +1390,7 @@ class Parser var _line:Int; var _tag = tag; var _result:Dynamic = usingMaps ? new ObjectMap<{}, Dynamic>() : {}; - + var keyTag:Dynamic = null; var keyNode:Dynamic = null; var valueNode:Dynamic = null; @@ -1410,11 +1410,11 @@ class Parser (CHAR_SPACE == following || CHAR_TAB == following || CHAR_LINE_FEED == following || - CHAR_CARRIAGE_RETURN == following)) + CHAR_CARRIAGE_RETURN == following)) { - if (CHAR_QUESTION == character) + if (CHAR_QUESTION == character) { - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); @@ -1427,15 +1427,15 @@ class Parser atExplicitKey = true; allowCompact = true; - } - else if (atExplicitKey) + } + else if (atExplicitKey) { // i.e. CHAR_COLON == character after the explicit key. atExplicitKey = false; allowCompact = true; - } - else + } + else { throwError('incomplete explicit mapping pair; a key node is missed'); } @@ -1444,36 +1444,36 @@ class Parser character = following; } - else if (composeNode(nodeIndent, CONTEXT_FLOW_OUT, false, true)) + else if (composeNode(nodeIndent, CONTEXT_FLOW_OUT, false, true)) { if (line == _line) { // TODO: Remove this cycle when the flow readers will consume // trailing whitespaces like the block readers. - while (CHAR_SPACE == character || CHAR_TAB == character) + while (CHAR_SPACE == character || CHAR_TAB == character) { character = Utf8.charCodeAt(input, ++position); } - if (CHAR_COLON == character) + if (CHAR_COLON == character) { character = Utf8.charCodeAt(input, ++position); if (CHAR_SPACE != character && CHAR_TAB != character && CHAR_LINE_FEED != character && - CHAR_CARRIAGE_RETURN != character) + CHAR_CARRIAGE_RETURN != character) { throwError('a whitespace character is expected after the key-value separator within a block mapping'); } - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); else storeObjectMappingPair(_result, keyTag, keyNode, null); - + keyTag = keyNode = valueNode = null; } @@ -1483,37 +1483,37 @@ class Parser keyTag = tag; keyNode = result; - } - else if (detected) + } + else if (detected) { throwError('can not read an implicit mapping pair; a colon is missed'); - } - else + } + else { tag = _tag; return true; // Keep the result of `composeNode`. } } - else if (detected) + else if (detected) { throwError('can not read a block mapping entry; a multiline key may not be an implicit key'); } - else + else { tag = _tag; return true; // Keep the result of `composeNode`. } - } - else + } + else { break; } - if (line == _line || lineIndent > nodeIndent) + if (line == _line || lineIndent > nodeIndent) { - if (composeNode(nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) + if (composeNode(nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { if (atExplicitKey) keyNode = result; @@ -1521,7 +1521,7 @@ class Parser valueNode = result; } - if (!atExplicitKey) + if (!atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, valueNode); @@ -1536,17 +1536,17 @@ class Parser skipSeparationSpace(true, -1); } - if (lineIndent > nodeIndent && position < length) + if (lineIndent > nodeIndent && position < length) { throwError('bad indentation of a mapping entry'); - } - else if (lineIndent < nodeIndent) + } + else if (lineIndent < nodeIndent) { break; } } - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); @@ -1554,7 +1554,7 @@ class Parser storeObjectMappingPair(_result, keyTag, keyNode, null); } - if (detected) + if (detected) { tag = _tag; kind = KIND_OBJECT; @@ -1564,7 +1564,7 @@ class Parser return detected; } - function readTagProperty() + function readTagProperty() { var _position:Int; var isVerbatim = false; @@ -1591,7 +1591,7 @@ class Parser isNamed = true; tagHandle = '!!'; character = Utf8.charCodeAt(input, ++position); - } + } else { tagHandle = '!'; @@ -1604,7 +1604,7 @@ class Parser do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_GREATER_THAN != character); - if (position < length) + if (position < length) { tagName = yaml.util.Utf8.substring(input, _position, position); character = Utf8.charCodeAt(input, ++position); @@ -1674,7 +1674,7 @@ class Parser { tag = 'tag:yaml.org,2002:' + tagName; } - else + else { throwError('undeclared tag handle "' + tagHandle + '"'); } @@ -1704,7 +1704,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET != character && CHAR_RIGHT_SQUARE_BRACKET != character && CHAR_LEFT_CURLY_BRACKET != character && - CHAR_RIGHT_CURLY_BRACKET != character) + CHAR_RIGHT_CURLY_BRACKET != character) { character = Utf8.charCodeAt(input, ++position); } @@ -1716,7 +1716,7 @@ class Parser return true; } - function readAlias() + function readAlias() { var _position:Int; var alias:String; @@ -1745,12 +1745,12 @@ class Parser throwError('name of an alias node must contain at least one character'); alias = yaml.util.Utf8.substring(input, _position, position); - + if (!anchorMap.exists(alias)) throwError('unidentified alias "' + alias + '"'); result = anchorMap.get(alias); - + skipSeparationSpace(true, -1); return true; } @@ -1801,7 +1801,7 @@ class Parser character = Utf8.charCodeAt(input, ++position); } - if (CHAR_SHARP == character) + if (CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); @@ -1825,12 +1825,12 @@ class Parser directiveArgs.push(yaml.util.Utf8.substring(input, _position, position)); } - if (position < length) + if (position < length) { readLineBreak(); } - if (directiveHandlers.exists(directiveName)) + if (directiveHandlers.exists(directiveName)) { directiveHandlers.get(directiveName)(directiveName, directiveArgs); } @@ -1878,11 +1878,11 @@ class Parser return; } - if (position < length) + if (position < length) { throwError('end of the stream or a document separator is expected'); - } - else + } + else { return; } @@ -1954,7 +1954,7 @@ class Parser public static inline var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */ - public static var SIMPLE_ESCAPE_SEQUENCES:IntMap = + public static var SIMPLE_ESCAPE_SEQUENCES:IntMap = { var hash = new IntMap(); hash.set(CHAR_DIGIT_ZERO, createUtf8Char(0x00));// '\x00'); @@ -1977,7 +1977,7 @@ class Parser hash.set(CHAR_CAPITAL_P, createUtf8Char(0x2029));//'\u2029'); hash; }; - + static function createUtf8Char(hex:Int):String { var utf8 = new Utf8(1); @@ -1985,7 +1985,7 @@ class Parser return utf8.toString(); } - public static var HEXADECIMAL_ESCAPE_SEQUENCES:IntMap = + public static var HEXADECIMAL_ESCAPE_SEQUENCES:IntMap = { var hash = new IntMap(); hash.set(CHAR_SMALL_X, 2); @@ -1994,22 +1994,22 @@ class Parser hash; }; - #if (neko || cpp || display) + #if (neko || cpp || display || php) public static var PATTERN_NON_PRINTABLE = ~/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}-\x{84}\x{86}-\x{9F}\x{FFFE}\x{FFFF}]/u; #elseif (js || flash9 || java) - public static var PATTERN_NON_PRINTABLE = ~/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uD800-\uDFFF\uFFFE\uFFFF]/u; + public static var PATTERN_NON_PRINTABLE = ~/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uD800-\uDFFF\uFFFE\uFFFF]/u; #else #error "Compilation target not supported due to lack of Unicode RegEx support." #end - - #if (neko || cpp || display) + + #if (neko || cpp || display || php) public static var PATTERN_NON_ASCII_LINE_BREAKS = ~/[\x{85}\x{2028}\x{2029}]/u; #elseif (js || flash9 || java) public static var PATTERN_NON_ASCII_LINE_BREAKS = ~/[\x85\u2028\u2029]/u; #else #error "Compilation target not supported due to lack of Unicode RegEx support." #end - + public static var PATTERN_FLOW_INDICATORS = ~/[,\[\]\{\}]/u; public static var PATTERN_TAG_HANDLE = ~/^(?:!|!!|![a-z\-]+!)$/iu; public static var PATTERN_TAG_URI = ~/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/iu; diff --git a/src/yaml/type/YTimestamp.hx b/src/yaml/type/YTimestamp.hx index 964e6bb..280e7c4 100644 --- a/src/yaml/type/YTimestamp.hx +++ b/src/yaml/type/YTimestamp.hx @@ -16,7 +16,7 @@ class YTimestamp extends YamlType '(?:\\.([0-9]*))?' + // [7] fraction '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour '(?::([0-9][0-9]))?))?)?$', "iu"); // [11] tz_minute - + public function new() { super('tag:yaml.org,2002:timestamp', {kind:"string"}, {kind:"object", instanceOf:Date}); @@ -37,7 +37,7 @@ class YTimestamp extends YamlType var fraction:Null = 0; var delta:Null = 0; - try + try { year = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(1)); month = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(2)) - 1; // month starts with 0 @@ -45,7 +45,7 @@ class YTimestamp extends YamlType hour = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(4)); minute = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(5)); second = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(6)); - + // EReg.matched doesn't throw exception under neko for whatever reason so we need to // check for null on each matched call var matched = -1; @@ -55,26 +55,26 @@ class YTimestamp extends YamlType if (hour == null) matched = hour = 0; if (minute == null) matched = minute = 0; if (second == null) matched = second = 0; - + if (matched == 0) throw "Nothing left to match"; var msecs = YAML_TIMESTAMP_REGEXP.matched(7); - if (msecs == null) + if (msecs == null) throw "Nothing left to match"; - + var f = msecs.substring(0, 3); while (f.length < 3) f += '0'; - + fraction = Std.parseInt(f); - + if (YAML_TIMESTAMP_REGEXP.matched(9) != null) { var tz_hour:Null = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(10)); if (tz_hour == null) throw "Nothing left to match"; - + var tz_minute:Null = 0; try { tz_minute = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(11)); @@ -82,7 +82,7 @@ class YTimestamp extends YamlType tz_minute = 0; } catch(e:Dynamic) {} - + delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds if ('-' == YAML_TIMESTAMP_REGEXP.matched(9)) delta = -delta; @@ -92,15 +92,15 @@ class YTimestamp extends YamlType #if (js || flash) var stamp:Float = nativeDate().UTC(year, month, day, hour, minute, second, fraction); - + if (delta != 0) stamp = stamp - delta; - + return Date.fromTime(stamp); - + #else trace("Warning: UTC dates are not supported under this target"); - + var date = new Date(year, month, day, hour, minute, second); // if (delta != 0) // stamp = stamp - delta; @@ -130,6 +130,6 @@ class YTimestamp extends YamlType trace("Warning: UTC dates are not supported under this target"); return object.toString(); #end - + } } diff --git a/test/TestPhp.hx b/test/TestPhp.hx new file mode 100644 index 0000000..ada12de --- /dev/null +++ b/test/TestPhp.hx @@ -0,0 +1,25 @@ +package; + +import yaml.type.*; +import yaml.YamlTest; +import utest.Runner; +import utest.ui.Report; + +class TestPhp { + static public function main() { + var runner = new Runner(); + runner.addCase(new YPairsTest()); + runner.addCase(new YIntTest()); + runner.addCase(new YBoolTest()); + runner.addCase(new YSetTest()); + runner.addCase(new YMergeTest()); + runner.addCase(new YFloatTest()); + runner.addCase(new YOmapTest()); + runner.addCase(new YTimestampTest()); + runner.addCase(new YBinaryTest()); + runner.addCase(new YNullTest()); + runner.addCase(new YamlTest()); + Report.create(runner); + runner.run(); + } +} \ No newline at end of file diff --git a/test/TestSuite.hx b/test/TestSuite.hx index 2c55d1c..f40f0ed 100644 --- a/test/TestSuite.hx +++ b/test/TestSuite.hx @@ -1,15 +1,15 @@ import massive.munit.TestSuite; -import yaml.type.YBinaryTest; -import yaml.type.YBoolTest; -import yaml.type.YFloatTest; +import yaml.type.YPairsTest; import yaml.type.YIntTest; +import yaml.type.YBoolTest; +import yaml.type.YSetTest; import yaml.type.YMergeTest; -import yaml.type.YNullTest; +import yaml.type.YFloatTest; import yaml.type.YOmapTest; -import yaml.type.YPairsTest; -import yaml.type.YSetTest; import yaml.type.YTimestampTest; +import yaml.type.YBinaryTest; +import yaml.type.YNullTest; import yaml.YamlTest; /** @@ -24,16 +24,16 @@ class TestSuite extends massive.munit.TestSuite { super(); - add(yaml.type.YBinaryTest); - add(yaml.type.YBoolTest); - add(yaml.type.YFloatTest); + add(yaml.type.YPairsTest); add(yaml.type.YIntTest); + add(yaml.type.YBoolTest); + add(yaml.type.YSetTest); add(yaml.type.YMergeTest); - add(yaml.type.YNullTest); + add(yaml.type.YFloatTest); add(yaml.type.YOmapTest); - add(yaml.type.YPairsTest); - add(yaml.type.YSetTest); add(yaml.type.YTimestampTest); + add(yaml.type.YBinaryTest); + add(yaml.type.YNullTest); add(yaml.YamlTest); } } diff --git a/test/munit_compat/massive/munit/Assert.hx b/test/munit_compat/massive/munit/Assert.hx new file mode 100644 index 0000000..7059d63 --- /dev/null +++ b/test/munit_compat/massive/munit/Assert.hx @@ -0,0 +1,25 @@ +package massive.munit; + +import haxe.PosInfos; + +class Assert { + static public function areEqual(a:Dynamic, b:Dynamic, ?pos:PosInfos) { + utest.Assert.equals(a, b, pos); + } + + static public function isFalse(a:Bool, ?pos:PosInfos) { + utest.Assert.isFalse(a, pos); + } + + static public function isTrue(a:Bool, ?pos:PosInfos) { + utest.Assert.isTrue(a, pos); + } + + static public function isNull(a:Dynamic, ?pos:PosInfos) { + utest.Assert.isNull(a, pos); + } + + static public function fail(str:String, ?pos:PosInfos) { + utest.Assert.fail(str, pos); + } +} \ No newline at end of file diff --git a/test/test.hxml b/test/test.hxml index c4a0694..960b21b 100644 --- a/test/test.hxml +++ b/test/test.hxml @@ -50,4 +50,31 @@ #-D HXCPP_M64 -cpp bin/cpp_test +--next + +## PHP7 +-main TestPhp +-lib hamcrest +-lib utest +-cp src +-resource resource/small_sample.yaml@small +-resource resource/sample.yaml@large + +-cp test/munit_compat +-cp test +-D php7 +-php bin/php7 +--next + +## PHP +-main TestPhp +-lib hamcrest +-lib utest +-cp src +-resource resource/small_sample.yaml@small +-resource resource/sample.yaml@large + +-cp test/munit_compat +-cp test +-php bin/php diff --git a/test/yaml/YamlTest.hx b/test/yaml/YamlTest.hx index f787351..67d8687 100644 --- a/test/yaml/YamlTest.hx +++ b/test/yaml/YamlTest.hx @@ -10,25 +10,28 @@ class YamlTest var smallSample:String; var largeSample:String; + public function new() init(); + @BeforeClass public function init() { smallSample = haxe.Resource.getString("small"); largeSample = haxe.Resource.getString("large"); } - + @TestDebug - public function shouldParseYaml() + public function testShouldParseYaml() { var time = haxe.Timer.stamp(); // var data:Dynamic = Yaml.parse(smallSample, Parser.options().useObjects()); var data:Dynamic = Yaml.parse(largeSample, Parser.options().useObjects()); trace((haxe.Timer.stamp() - time)); - + #if sys Yaml.write("bin/test/output.yaml", data); #else trace(Yaml.render(data)); #end + Assert.isTrue(true); } } diff --git a/test/yaml/type/YBinaryTest.hx b/test/yaml/type/YBinaryTest.hx index 769bb73..e4d7ff3 100644 --- a/test/yaml/type/YBinaryTest.hx +++ b/test/yaml/type/YBinaryTest.hx @@ -5,8 +5,10 @@ import massive.munit.Assert; class YBinaryTest { + public function new() {} + @Test - public function shouldResolveAndRepresentBinary() + public function testShouldResolveAndRepresentBinary() { var type = new YBinary(); var data:Bytes = cast type.resolve(createValue()); diff --git a/test/yaml/type/YBoolTest.hx b/test/yaml/type/YBoolTest.hx index 815cabe..267b983 100644 --- a/test/yaml/type/YBoolTest.hx +++ b/test/yaml/type/YBoolTest.hx @@ -7,26 +7,28 @@ class YBoolTest { var type:AnyYamlType; + public function new() {} + @Before - public function before() + public function setup() { type = new YBool(); } - + @Test - public function shouldResolveExplicitValues() + public function testShouldResolveExplicitValues() { var pos = ["true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES", "on", "On", "ON"]; for (value in pos) Assert.isTrue(type.resolve(value, true, true)); - + var neg = ["n", "N", "no", "No", "NO", "false", "False", "FALSE", "off", "Off", "OFF"]; for (value in neg) Assert.isFalse(type.resolve(value, true, true)); } @Test - public function shouldResolveImplicitValues() + public function testShouldResolveImplicitValues() { var pos = ["true", "True", "TRUE"]; for (value in pos) @@ -36,9 +38,9 @@ class YBoolTest for (value in neg) Assert.isFalse(type.resolve(value, true, false)); } - + @Test - public function shouldNotResolveExplicitValueWhenImplicit() + public function testShouldNotResolveExplicitValueWhenImplicit() { var values = ["y", "Y", "yes", "Yes", "YES", "on", "On", "ON", "n", "N", "no", "No", "NO", "off", "Off", "OFF"]; while (values.length > 0) @@ -55,7 +57,7 @@ class YBoolTest } @Test - public function shouldRepresentValue() + public function testShouldRepresentValue() { Assert.areEqual(type.represent(true, "uppercase"), "TRUE"); Assert.areEqual(type.represent(false, "uppercase"), "FALSE"); diff --git a/test/yaml/type/YFloatTest.hx b/test/yaml/type/YFloatTest.hx index cf26f23..c140c31 100644 --- a/test/yaml/type/YFloatTest.hx +++ b/test/yaml/type/YFloatTest.hx @@ -7,39 +7,41 @@ class YFloatTest { var type:YFloat; + public function new() {} + @Before - public function before() + public function setup() { type = new YFloat(); } @Test - public function shouldResolveFloat() + public function testShouldResolveFloat() { var const = 685230.15; - + var values = ["6.8523015e+5", "685.230_15e+03", "685_230.15", "190:20:30.15"]; for (value in values) Assert.areEqual(const, type.resolve(value)); - + Assert.areEqual(Math.NEGATIVE_INFINITY, type.resolve("-.inf")); Assert.areEqual(Math.POSITIVE_INFINITY, type.resolve(".inf")); Assert.isTrue(Math.isNaN(type.resolve(".NaN"))); } @Test - public function shouldRepresentFloat() + public function testShouldRepresentFloat() { Assert.areEqual("685230.15", type.represent(685230.15)); - + Assert.areEqual(".inf", type.represent(Math.POSITIVE_INFINITY, "lowercase")); Assert.areEqual(".INF", type.represent(Math.POSITIVE_INFINITY, "uppercase")); Assert.areEqual(".Inf", type.represent(Math.POSITIVE_INFINITY, "camelcase")); - + Assert.areEqual("-.inf", type.represent(Math.NEGATIVE_INFINITY, "lowercase")); Assert.areEqual("-.INF", type.represent(Math.NEGATIVE_INFINITY, "uppercase")); Assert.areEqual("-.Inf", type.represent(Math.NEGATIVE_INFINITY, "camelcase")); - + Assert.areEqual(".nan", type.represent(Math.NaN, "lowercase")); Assert.areEqual(".NAN", type.represent(Math.NaN, "uppercase")); Assert.areEqual(".NaN", type.represent(Math.NaN, "camelcase")); diff --git a/test/yaml/type/YIntTest.hx b/test/yaml/type/YIntTest.hx index 8bc5b4a..cbacc96 100644 --- a/test/yaml/type/YIntTest.hx +++ b/test/yaml/type/YIntTest.hx @@ -8,14 +8,16 @@ class YIntTest var type:YInt; + public function new() {} + @Before - public function before() + public function setup() { type = new YInt(); } @Test - public function shouldResolveInt() + public function testShouldResolveInt() { var canonical = "685230"; var decimal = "+685_230"; @@ -25,7 +27,7 @@ class YIntTest var binaryA = "0b1010_0111_0100_1010_1110"; var binaryB = "0b10100111010010101110"; var sexagesimal = "190:20:30"; - + Assert.areEqual(CONST, type.resolve(canonical)); Assert.areEqual(CONST, type.resolve(decimal)); Assert.areEqual(CONST, type.resolve(octal)); @@ -37,7 +39,7 @@ class YIntTest } @Test - public function shouldRepresentInt() + public function testShouldRepresentInt() { Assert.areEqual("0b10100111010010101110", type.represent(CONST, "binary")); Assert.areEqual("02472256", type.represent(CONST, "octal")); diff --git a/test/yaml/type/YMergeTest.hx b/test/yaml/type/YMergeTest.hx index 5f9d15a..d7ae839 100644 --- a/test/yaml/type/YMergeTest.hx +++ b/test/yaml/type/YMergeTest.hx @@ -5,12 +5,14 @@ import massive.munit.Assert; class YMergeTest { + public function new() {} + @Test - public function shouldResolveMerge() + public function testShouldResolveMerge() { var type = new YMerge(); Assert.areEqual("<<", type.resolve("<<")); - + try { type.resolve(""); Assert.fail("Should not resolve merge on any value but '<<'"); diff --git a/test/yaml/type/YNullTest.hx b/test/yaml/type/YNullTest.hx index 494dc88..714f948 100644 --- a/test/yaml/type/YNullTest.hx +++ b/test/yaml/type/YNullTest.hx @@ -7,20 +7,22 @@ class YNullTest { var type:YNull; + public function new() {} + @Before - public function before() + public function setup() { type = new YNull(); } @Test - public function shouldResolveNull() + public function testShouldResolveNull() { Assert.isNull(type.resolve("null")); Assert.isNull(type.resolve("Null")); Assert.isNull(type.resolve("NULL")); Assert.isNull(type.resolve("~")); - + try { type.resolve("some value"); Assert.fail("Should not resolve non-null value"); @@ -30,7 +32,7 @@ class YNullTest } @Test - public function shouldRepresentNull() + public function testShouldRepresentNull() { Assert.areEqual("~", type.represent(null, "canonical")); Assert.areEqual("null", type.represent(null, "lowercase")); diff --git a/test/yaml/type/YOmapTest.hx b/test/yaml/type/YOmapTest.hx index 341574a..050772f 100644 --- a/test/yaml/type/YOmapTest.hx +++ b/test/yaml/type/YOmapTest.hx @@ -8,8 +8,10 @@ class YOmapTest { var type:YOmap; + public function new() {} + @Before - public function before() + public function setup() { type = new YOmap(); } @@ -18,7 +20,7 @@ class YOmapTest @Ignore("CPP seems to be passing arrays by value(?) so comparison check fails") #end @Test - public function shouldAllowValidOmap() + public function testShouldAllowValidOmap() { var value:Array = [map("key01", "value01"), map("key02", "value02")]; shouldPass(value); @@ -26,9 +28,9 @@ class YOmapTest var value:Array = [map("key01", null), map("key02", null)]; shouldPass(value); } - + @Test - public function shouldFailInvalidOmap() + public function testShouldFailInvalidOmap() { var value:Array = [map("key01", "value01"), map("key01", "value02")]; shouldFail(value); @@ -50,7 +52,9 @@ class YOmapTest type.resolve(value); Assert.fail("Expected failure of omap resolution but succeeded. " + value); } - catch(e:ResolveTypeException) {} + catch(e:ResolveTypeException) { + Assert.isTrue(true); + } } function map(key:Dynamic, value:Dynamic):AnyObjectMap diff --git a/test/yaml/type/YPairsTest.hx b/test/yaml/type/YPairsTest.hx index b35f07a..5777eca 100644 --- a/test/yaml/type/YPairsTest.hx +++ b/test/yaml/type/YPairsTest.hx @@ -8,14 +8,16 @@ class YPairsTest { var type:YPairs; + public function new() {} + @Before - public function before() + public function setup() { type = new YPairs(); } @Test - public function shouldAllowValidPair() + public function testShouldAllowValidPair() { var value:Array = [map("key01", "value01"), map("key02", "value02")]; shouldPass(value); @@ -28,7 +30,7 @@ class YPairsTest } @Test - public function shouldFailInvalidOmap() + public function testShouldFailInvalidOmap() { var m = map("key01", "value01"); m.set("key02", "value02"); @@ -40,13 +42,13 @@ class YPairsTest { var result = type.resolve(value); Assert.areEqual(value.length, result.length); - + for (i in 0...value.length) { var key = null; for (k in value[i].keys()) key = k; - + Assert.areEqual(result[i][0], key); Assert.areEqual(result[i][1], value[i].get(key)); } @@ -58,7 +60,9 @@ class YPairsTest type.resolve(value); Assert.fail("Expected failure of pairs resolution but succeeded. " + value); } - catch(e:ResolveTypeException) {} + catch(e:ResolveTypeException) { + Assert.isTrue(true); + } } function map(key:Dynamic, value:Dynamic):AnyObjectMap diff --git a/test/yaml/type/YSetTest.hx b/test/yaml/type/YSetTest.hx index ba14d9d..d1482ae 100644 --- a/test/yaml/type/YSetTest.hx +++ b/test/yaml/type/YSetTest.hx @@ -6,29 +6,31 @@ import massive.munit.Assert; class YSetTest { + public function new() {} + @Test - public function shouldOnlyAllowNullValuesInMaps() + public function testShouldOnlyAllowNullValuesInMaps() { var type = new YSet(); var map = new AnyObjectMap(); map.set("key", "value"); - + try { type.resolve(map); Assert.fail("Expcted failure due to map having non-null value"); } catch(e:ResolveTypeException) { - + Assert.isTrue(true); } } @Test - public function shouldAllowMapsWithNullValue() + public function testShouldAllowMapsWithNullValue() { var type = new YSet(); var map = new AnyObjectMap(); map.set("key", null); - + Assert.areEqual(map, type.resolve(map)); } diff --git a/test/yaml/type/YTimestampTest.hx b/test/yaml/type/YTimestampTest.hx index 0ed9c9d..cc05464 100644 --- a/test/yaml/type/YTimestampTest.hx +++ b/test/yaml/type/YTimestampTest.hx @@ -8,17 +8,21 @@ class YTimestampTest var type:YTimestamp; + public function new() {} + @Before - public function before() + public function setup() { type = new YTimestamp(); } #if !(js || flash) @Ignore("UTC Dates not supported on this target") - #end @Test - public function shouldResolveTimestamp() + public function testShouldResolveTimestamp() Assert.isTrue(true); + #else + @Test + public function testShouldResolveTimestamp() { var canonical = "2001-12-15T02:59:43.1Z"; var validIso8601 = "2001-12-14t21:59:43.10-05:00"; @@ -26,20 +30,24 @@ class YTimestampTest var noTimeZone = "2001-12-15 2:59:43.10"; var date = "2002-12-14"; var time:Float = 1039824000000; - + Assert.areEqual(STAMP, type.resolve(canonical).getTime()); Assert.areEqual(STAMP, type.resolve(validIso8601).getTime()); Assert.areEqual(STAMP, type.resolve(spaceSeparated).getTime()); Assert.areEqual(STAMP, type.resolve(noTimeZone).getTime()); Assert.areEqual(time, type.resolve(date).getTime()); } + #end #if !(js || flash) @Ignore("UTC Dates not supported on this target") - #end @Test - public function shouldRepresentTimestamp() + public function testShouldRepresentTimestamp() Assert.isTrue(true); + #else + @Test + public function testShouldRepresentTimestamp() { Assert.areEqual("2001-12-15T02:59:43.100Z", type.represent(Date.fromTime(STAMP))); } + #end } From 9fe8f3c55688f34d80bf4699a670eab6cfe50eb1 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Sun, 5 Feb 2017 11:13:27 +0300 Subject: [PATCH 2/2] get trailing spaces back --- src/yaml/Parser.hx | 328 ++++++++++++++++++------------------ src/yaml/type/YTimestamp.hx | 30 ++-- test/TestSuite.hx | 24 +-- 3 files changed, 191 insertions(+), 191 deletions(-) diff --git a/src/yaml/Parser.hx b/src/yaml/Parser.hx index 588ad00..418f39f 100644 --- a/src/yaml/Parser.hx +++ b/src/yaml/Parser.hx @@ -21,12 +21,12 @@ class ParserOptions public var maps:Bool; /** - @param schema Defines the schema to use while parsing. Defaults to yaml.schema.DefaultSchema. + @param schema Defines the schema to use while parsing. Defaults to yaml.schema.DefaultSchema. */ public function new(?schema:Schema = null) { this.schema = (schema == null) ? new DefaultSchema() : schema; - + strict = false; resolve = true; validation = true; @@ -34,8 +34,8 @@ class ParserOptions } /** - Use yaml.util.ObjectMap as the key => value container. - + Use yaml.util.ObjectMap as the key => value container. + Allows for complex key values. */ public function useMaps():ParserOptions @@ -46,7 +46,7 @@ class ParserOptions /** Use Dynamic objects as the key => value container. - + All keys will become Strings. */ public function useObjects():ParserOptions @@ -57,7 +57,7 @@ class ParserOptions /** Defines the schema to use while parsing. - + See yaml.Schema */ public function setSchema(schema:Schema):ParserOptions @@ -88,13 +88,13 @@ class ParserOptions class Parser { /** - Utility method to create ParserOptions for configuring a Parser instance. + Utility method to create ParserOptions for configuring a Parser instance. */ public static function options():ParserOptions { return new ParserOptions(); } - + var schema:Schema; var resolve:Bool; var validate:Bool; @@ -137,7 +137,7 @@ class Parser options.schema = new SafeSchema(); return parse(input, options); } - + public function parse(input:String, options:ParserOptions):Dynamic { var result:Dynamic = null; @@ -145,11 +145,11 @@ class Parser var responder = function (data:Dynamic) { - if (!received) + if (!received) { result = data; received = true; - } + } else { throw new YamlException('expected a single document in the stream, but found more'); @@ -160,7 +160,7 @@ class Parser return result; } - + public function parseAll(input:String, output:Dynamic->Void, options:ParserOptions):Void { #if (neko || cpp) @@ -168,9 +168,9 @@ class Parser #else this.input = input; #end - + this.output = output; - + schema = options.schema; resolve = options.resolve; validate = options.validation; @@ -225,7 +225,7 @@ class Parser for (i in 0...args.length) args[i] = Utf8.encode(args[i]); #end - + var handle:String; var prefix:String; @@ -263,18 +263,18 @@ class Parser readDocument(); } } - - function generateError(message:String, ?info:PosInfos) + + function generateError(message:String, ?info:PosInfos) { return new YamlException(message, info); } - function throwError(message:String, ?info:PosInfos) + function throwError(message:String, ?info:PosInfos) { throw generateError(message, info); } - function throwWarning(message:String, ?info:PosInfos) + function throwWarning(message:String, ?info:PosInfos) { var error = generateError(message, info); @@ -289,11 +289,11 @@ class Parser { var _result:String; - if (start < end) + if (start < end) { _result = yaml.util.Utf8.substring(input, start, end); - if (checkJson && validate) + if (checkJson && validate) { for (pos in 0...Utf8.length(_result))//.length) { @@ -306,31 +306,31 @@ class Parser result += _result; } } - + // when create dynamic object graph function mergeObjectMappings(destination:Dynamic, source:Dynamic) { if (Type.typeof(source) != ValueType.TObject) { throwError('cannot merge mappings; the provided source object is unacceptable'); } - + for (key in Reflect.fields(source)) if (!Reflect.hasField(destination, key)) Reflect.setField(destination, key, Reflect.field(source, key)); } - + // when creating map based graph function mergeMappings(destination:AnyObjectMap, source:AnyObjectMap) { if (!Std.is(source, AnyObjectMap)) { throwError('cannot merge mappings; the provided source object is unacceptable'); } - + for (key in source.keys()) if (!destination.exists(key)) destination.set(key, source.get(key)); } - + function storeObjectMappingPair(_result:Dynamic, keyTag:String, keyNode:Dynamic, valueNode:Dynamic):Dynamic { @@ -366,7 +366,7 @@ class Parser if ('tag:yaml.org,2002:merge' == keyTag) { - if (Std.is(valueNode, Array)) + if (Std.is(valueNode, Array)) { var list:Array = cast valueNode; for (member in list) @@ -389,13 +389,13 @@ class Parser if (CHAR_LINE_FEED == character) { position += 1; - } + } else if (CHAR_CARRIAGE_RETURN == character) { if (CHAR_LINE_FEED == Utf8.charCodeAt(input, (position + 1))) { position += 2; - } + } else { position += 1; @@ -408,7 +408,7 @@ class Parser line += 1; lineStart = position; - + if (position < length) character = Utf8.charCodeAt(input, position); else @@ -421,12 +421,12 @@ class Parser while (position < length) { - while (CHAR_SPACE == character || CHAR_TAB == character) + while (CHAR_SPACE == character || CHAR_TAB == character) { character = Utf8.charCodeAt(input, ++position); } - if (allowComments && CHAR_SHARP == character) + if (allowComments && CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); @@ -448,8 +448,8 @@ class Parser { throwWarning('deficient indentation'); } - } - else + } + else { break; } @@ -460,17 +460,17 @@ class Parser function testDocumentSeparator() { - if (position == lineStart && + if (position == lineStart && (CHAR_MINUS == character || CHAR_DOT == character) && Utf8.charCodeAt(input, (position + 1)) == character && - Utf8.charCodeAt(input, (position + 2)) == character) + Utf8.charCodeAt(input, (position + 2)) == character) { var pos = position + 3; var char = Utf8.charCodeAt(input, pos); - if (pos >= length || CHAR_SPACE == char || CHAR_TAB == char || - CHAR_LINE_FEED == char || CHAR_CARRIAGE_RETURN == char) + if (pos >= length || CHAR_SPACE == char || CHAR_TAB == char || + CHAR_LINE_FEED == char || CHAR_CARRIAGE_RETURN == char) { return true; } @@ -479,7 +479,7 @@ class Parser return false; } - function writeFoldedLines(count:Int) + function writeFoldedLines(count:Int) { if (1 == count) { @@ -502,7 +502,7 @@ class Parser var captureStart:Int; var captureEnd:Int; var hasPendingContent; - + var _line:Int = 0; var _kind = kind; var _result = result; @@ -531,7 +531,7 @@ class Parser return false; } - if (CHAR_QUESTION == character || CHAR_MINUS == character) + if (CHAR_QUESTION == character || CHAR_MINUS == character) { following = Utf8.charCodeAt(input, position + 1); @@ -544,7 +544,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET == following || CHAR_RIGHT_SQUARE_BRACKET == following || CHAR_LEFT_CURLY_BRACKET == following || - CHAR_RIGHT_CURLY_BRACKET == following)) + CHAR_RIGHT_CURLY_BRACKET == following)) { return false; } @@ -557,7 +557,7 @@ class Parser while (position < length) { - if (CHAR_COLON == character) + if (CHAR_COLON == character) { following = Utf8.charCodeAt(input, position + 1); @@ -570,7 +570,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET == following || CHAR_RIGHT_SQUARE_BRACKET == following || CHAR_LEFT_CURLY_BRACKET == following || - CHAR_RIGHT_CURLY_BRACKET == following)) + CHAR_RIGHT_CURLY_BRACKET == following)) { break; } @@ -588,7 +588,7 @@ class Parser break; } - } + } else if ((position == lineStart && testDocumentSeparator()) || withinFlowCollection && (CHAR_COMMA == character || @@ -605,15 +605,15 @@ class Parser _line = line; var _lineStart = lineStart; var _lineIndent = lineIndent; - + skipSeparationSpace(false, -1); - if (lineIndent >= nodeIndent) + if (lineIndent >= nodeIndent) { hasPendingContent = true; continue; - } - else + } + else { position = captureEnd; line = _line; @@ -632,26 +632,26 @@ class Parser hasPendingContent = false; } - if (CHAR_SPACE != character && CHAR_TAB != character) + if (CHAR_SPACE != character && CHAR_TAB != character) { captureEnd = position + 1; } if (++position >= length) break; - + character = Utf8.charCodeAt(input, position); } captureSegment(captureStart, captureEnd, false); - if (result != null) + if (result != null) { #if sys result = Utf8.decode(result); // convert back into native encoding #end return true; - } + } else { kind = _kind; @@ -675,19 +675,19 @@ class Parser character = Utf8.charCodeAt(input, ++position); captureStart = captureEnd = position; - while (position < length) + while (position < length) { if (CHAR_SINGLE_QUOTE == character) { captureSegment(captureStart, position, true); character = Utf8.charCodeAt(input, ++position); - if (CHAR_SINGLE_QUOTE == character) + if (CHAR_SINGLE_QUOTE == character) { captureStart = captureEnd = position; character = Utf8.charCodeAt(input, ++position); - } - else + } + else { #if sys result = Utf8.decode(result); @@ -696,18 +696,18 @@ class Parser } } - else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { captureSegment(captureStart, captureEnd, true); writeFoldedLines(skipSeparationSpace(false, nodeIndent)); captureStart = captureEnd = position; character = Utf8.charCodeAt(input, position); - } - else if (position == lineStart && testDocumentSeparator()) + } + else if (position == lineStart && testDocumentSeparator()) { throwError('unexpected end of the document within a single quoted scalar'); - } - else + } + else { character = Utf8.charCodeAt(input, ++position); captureEnd = position; @@ -718,7 +718,7 @@ class Parser return false; } - function readDoubleQuotedScalar(nodeIndent:Int) + function readDoubleQuotedScalar(nodeIndent:Int) { var captureStart:Int; var captureEnd:Int; @@ -749,11 +749,11 @@ class Parser captureSegment(captureStart, position, true); character = Utf8.charCodeAt(input, ++position); - if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { skipSeparationSpace(false, nodeIndent); } - else if (SIMPLE_ESCAPE_SEQUENCES.exists(character)) + else if (SIMPLE_ESCAPE_SEQUENCES.exists(character)) { result += SIMPLE_ESCAPE_SEQUENCES.get(character); character = Utf8.charCodeAt(input, ++position); @@ -789,14 +789,14 @@ class Parser character = Utf8.charCodeAt(input, ++position); } - else + else { throwError('unknown escape sequence'); } captureStart = captureEnd = position; - } + } else if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { captureSegment(captureStart, captureEnd, true); @@ -940,7 +940,7 @@ class Parser if (null == tag) tag = '?'; } - + if (null != anchor) { @@ -953,7 +953,7 @@ class Parser hasContent = allowBlockCollections && readBlockSequence(blockIndent); } } - + if (null != tag && '!' != tag) { var _result:Dynamic = null; @@ -969,7 +969,7 @@ class Parser // non-specific tag is only assigned to plain scalars. So, it isn't // needed to check for 'kind' conformity. var resolvedType = false; - + try { _result = type.resolve(result, usingMaps, false); @@ -982,7 +982,7 @@ class Parser resolvedType = true; } catch (e:ResolveTypeException) {} - + if (resolvedType) break; } } @@ -998,7 +998,7 @@ class Parser if (!t.loader.skip) { - + try { _result = t.resolve(result, usingMaps, true); @@ -1006,7 +1006,7 @@ class Parser if (Std.is(_result, String)) _result = Utf8.decode(_result); #end - + result = _result; } catch(e:ResolveTypeException) @@ -1020,7 +1020,7 @@ class Parser throwWarning('unknown tag !<' + tag + '>'); } } - + return (null != tag || null != anchor || hasContent); } @@ -1069,8 +1069,8 @@ class Parser kind = isMapping ? KIND_OBJECT : KIND_ARRAY; result = _result; return true; - } - else if (!readNext) + } + else if (!readNext) { throwError('missed comma between flow collection entries'); } @@ -1085,7 +1085,7 @@ class Parser if (CHAR_SPACE == following || CHAR_TAB == following || CHAR_LINE_FEED == following || - CHAR_CARRIAGE_RETURN == following) + CHAR_CARRIAGE_RETURN == following) { isPair = isExplicitPair = true; position += 1; @@ -1107,7 +1107,7 @@ class Parser composeNode(nodeIndent, CONTEXT_FLOW_IN, false, true); valueNode = result; } - + if (isMapping) { if (usingMaps) @@ -1115,14 +1115,14 @@ class Parser else storeObjectMappingPair(_result, keyTag, keyNode, valueNode); } - else if (isPair) + else if (isPair) { if (usingMaps) _result.push(storeMappingPair(null, keyTag, keyNode, valueNode)); else _result.push(storeObjectMappingPair(null, keyTag, keyNode, valueNode)); } - else + else { _result.push(keyNode); } @@ -1133,7 +1133,7 @@ class Parser { readNext = true; character = Utf8.charCodeAt(input, ++position); - } + } else { readNext = false; @@ -1144,7 +1144,7 @@ class Parser return false; } - function readBlockScalar(nodeIndent:Int) + function readBlockScalar(nodeIndent:Int) { var captureStart:Int; var folding:Bool; @@ -1153,7 +1153,7 @@ class Parser var textIndent = nodeIndent; var emptyLines = -1; - switch (character) + switch (character) { case CHAR_VERTICAL_LINE: folding = false; @@ -1168,17 +1168,17 @@ class Parser kind = KIND_STRING; result = ''; - while (position < length) + while (position < length) { character = Utf8.charCodeAt(input, ++position); - if (CHAR_PLUS == character || CHAR_MINUS == character) + if (CHAR_PLUS == character || CHAR_MINUS == character) { - if (CHOMPING_CLIP == chomping) + if (CHOMPING_CLIP == chomping) { chomping = (CHAR_PLUS == character) ? CHOMPING_KEEP : CHOMPING_STRIP; } - else + else { throwError('repeat of a chomping mode identifier'); } @@ -1200,7 +1200,7 @@ class Parser throwError('repeat of an indentation width identifier'); } } - else + else { break; } @@ -1211,19 +1211,19 @@ class Parser do { character = Utf8.charCodeAt(input, ++position); } while (CHAR_SPACE == character || CHAR_TAB == character); - if (CHAR_SHARP == character) + if (CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); } } - while (position < length) + while (position < length) { readLineBreak(); lineIndent = 0; - while ((!detectedIndent || lineIndent < textIndent) && (CHAR_SPACE == character)) + while ((!detectedIndent || lineIndent < textIndent) && (CHAR_SPACE == character)) { lineIndent += 1; character = Utf8.charCodeAt(input, ++position); @@ -1234,24 +1234,24 @@ class Parser textIndent = lineIndent; } - if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) + if (CHAR_LINE_FEED == character || CHAR_CARRIAGE_RETURN == character) { emptyLines += 1; continue; } // End of the scalar. Perform the chomping. - if (lineIndent < textIndent) + if (lineIndent < textIndent) { - if (CHOMPING_KEEP == chomping) + if (CHOMPING_KEEP == chomping) { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); #else result += Strings.repeat('\n', emptyLines + 1); #end - } - else if (CHOMPING_CLIP == chomping) + } + else if (CHOMPING_CLIP == chomping) { result += '\n'; } @@ -1260,9 +1260,9 @@ class Parser detectedIndent = true; - if (folding) + if (folding) { - if (CHAR_SPACE == character || CHAR_TAB == character) + if (CHAR_SPACE == character || CHAR_TAB == character) { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); @@ -1271,17 +1271,17 @@ class Parser #end emptyLines = 1; } - else if (0 == emptyLines) + else if (0 == emptyLines) { #if sys result += Utf8.encode(' '); #else result += ' '; #end - + emptyLines = 0; - } - else + } + else { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines)); @@ -1290,8 +1290,8 @@ class Parser #end emptyLines = 0; } - } - else + } + else { #if sys result += Utf8.encode(Strings.repeat('\n', emptyLines + 1)); @@ -1308,7 +1308,7 @@ class Parser captureSegment(captureStart, position, false); } - + #if sys result = Utf8.decode(result); #end @@ -1316,7 +1316,7 @@ class Parser return true; } - function readBlockSequence(nodeIndent:Int) + function readBlockSequence(nodeIndent:Int) { var _line:Int; var _tag = tag; @@ -1327,7 +1327,7 @@ class Parser if (null != anchor) anchorMap.set(anchor, _result); - while (position < length) + while (position < length) { if (CHAR_MINUS != character) break; @@ -1337,7 +1337,7 @@ class Parser if (CHAR_SPACE != following && CHAR_TAB != following && CHAR_LINE_FEED != following && - CHAR_CARRIAGE_RETURN != following) + CHAR_CARRIAGE_RETURN != following) { break; } @@ -1346,9 +1346,9 @@ class Parser position += 1; character = following; - if (skipSeparationSpace(true, -1) != 0) + if (skipSeparationSpace(true, -1) != 0) { - if (lineIndent <= nodeIndent) + if (lineIndent <= nodeIndent) { _result.push(null); continue; @@ -1360,24 +1360,24 @@ class Parser _result.push(result); skipSeparationSpace(true, -1); - if ((line == _line || lineIndent > nodeIndent) && position < length) + if ((line == _line || lineIndent > nodeIndent) && position < length) { throwError('bad indentation of a sequence entry'); } - else if (lineIndent < nodeIndent) + else if (lineIndent < nodeIndent) { break; } } - if (detected) + if (detected) { tag = _tag; kind = KIND_ARRAY; result = _result; return true; - } - else + } + else { return false; } @@ -1390,7 +1390,7 @@ class Parser var _line:Int; var _tag = tag; var _result:Dynamic = usingMaps ? new ObjectMap<{}, Dynamic>() : {}; - + var keyTag:Dynamic = null; var keyNode:Dynamic = null; var valueNode:Dynamic = null; @@ -1410,11 +1410,11 @@ class Parser (CHAR_SPACE == following || CHAR_TAB == following || CHAR_LINE_FEED == following || - CHAR_CARRIAGE_RETURN == following)) + CHAR_CARRIAGE_RETURN == following)) { - if (CHAR_QUESTION == character) + if (CHAR_QUESTION == character) { - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); @@ -1427,15 +1427,15 @@ class Parser atExplicitKey = true; allowCompact = true; - } - else if (atExplicitKey) + } + else if (atExplicitKey) { // i.e. CHAR_COLON == character after the explicit key. atExplicitKey = false; allowCompact = true; - } - else + } + else { throwError('incomplete explicit mapping pair; a key node is missed'); } @@ -1444,36 +1444,36 @@ class Parser character = following; } - else if (composeNode(nodeIndent, CONTEXT_FLOW_OUT, false, true)) + else if (composeNode(nodeIndent, CONTEXT_FLOW_OUT, false, true)) { if (line == _line) { // TODO: Remove this cycle when the flow readers will consume // trailing whitespaces like the block readers. - while (CHAR_SPACE == character || CHAR_TAB == character) + while (CHAR_SPACE == character || CHAR_TAB == character) { character = Utf8.charCodeAt(input, ++position); } - if (CHAR_COLON == character) + if (CHAR_COLON == character) { character = Utf8.charCodeAt(input, ++position); if (CHAR_SPACE != character && CHAR_TAB != character && CHAR_LINE_FEED != character && - CHAR_CARRIAGE_RETURN != character) + CHAR_CARRIAGE_RETURN != character) { throwError('a whitespace character is expected after the key-value separator within a block mapping'); } - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); else storeObjectMappingPair(_result, keyTag, keyNode, null); - + keyTag = keyNode = valueNode = null; } @@ -1483,37 +1483,37 @@ class Parser keyTag = tag; keyNode = result; - } - else if (detected) + } + else if (detected) { throwError('can not read an implicit mapping pair; a colon is missed'); - } - else + } + else { tag = _tag; return true; // Keep the result of `composeNode`. } } - else if (detected) + else if (detected) { throwError('can not read a block mapping entry; a multiline key may not be an implicit key'); } - else + else { tag = _tag; return true; // Keep the result of `composeNode`. } - } - else + } + else { break; } - if (line == _line || lineIndent > nodeIndent) + if (line == _line || lineIndent > nodeIndent) { - if (composeNode(nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) + if (composeNode(nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { if (atExplicitKey) keyNode = result; @@ -1521,7 +1521,7 @@ class Parser valueNode = result; } - if (!atExplicitKey) + if (!atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, valueNode); @@ -1536,17 +1536,17 @@ class Parser skipSeparationSpace(true, -1); } - if (lineIndent > nodeIndent && position < length) + if (lineIndent > nodeIndent && position < length) { throwError('bad indentation of a mapping entry'); - } - else if (lineIndent < nodeIndent) + } + else if (lineIndent < nodeIndent) { break; } } - if (atExplicitKey) + if (atExplicitKey) { if (usingMaps) storeMappingPair(_result, keyTag, keyNode, null); @@ -1554,7 +1554,7 @@ class Parser storeObjectMappingPair(_result, keyTag, keyNode, null); } - if (detected) + if (detected) { tag = _tag; kind = KIND_OBJECT; @@ -1564,7 +1564,7 @@ class Parser return detected; } - function readTagProperty() + function readTagProperty() { var _position:Int; var isVerbatim = false; @@ -1591,7 +1591,7 @@ class Parser isNamed = true; tagHandle = '!!'; character = Utf8.charCodeAt(input, ++position); - } + } else { tagHandle = '!'; @@ -1604,7 +1604,7 @@ class Parser do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_GREATER_THAN != character); - if (position < length) + if (position < length) { tagName = yaml.util.Utf8.substring(input, _position, position); character = Utf8.charCodeAt(input, ++position); @@ -1674,7 +1674,7 @@ class Parser { tag = 'tag:yaml.org,2002:' + tagName; } - else + else { throwError('undeclared tag handle "' + tagHandle + '"'); } @@ -1704,7 +1704,7 @@ class Parser CHAR_LEFT_SQUARE_BRACKET != character && CHAR_RIGHT_SQUARE_BRACKET != character && CHAR_LEFT_CURLY_BRACKET != character && - CHAR_RIGHT_CURLY_BRACKET != character) + CHAR_RIGHT_CURLY_BRACKET != character) { character = Utf8.charCodeAt(input, ++position); } @@ -1716,7 +1716,7 @@ class Parser return true; } - function readAlias() + function readAlias() { var _position:Int; var alias:String; @@ -1745,12 +1745,12 @@ class Parser throwError('name of an alias node must contain at least one character'); alias = yaml.util.Utf8.substring(input, _position, position); - + if (!anchorMap.exists(alias)) throwError('unidentified alias "' + alias + '"'); result = anchorMap.get(alias); - + skipSeparationSpace(true, -1); return true; } @@ -1801,7 +1801,7 @@ class Parser character = Utf8.charCodeAt(input, ++position); } - if (CHAR_SHARP == character) + if (CHAR_SHARP == character) { do { character = Utf8.charCodeAt(input, ++position); } while (position < length && CHAR_LINE_FEED != character && CHAR_CARRIAGE_RETURN != character); @@ -1825,12 +1825,12 @@ class Parser directiveArgs.push(yaml.util.Utf8.substring(input, _position, position)); } - if (position < length) + if (position < length) { readLineBreak(); } - if (directiveHandlers.exists(directiveName)) + if (directiveHandlers.exists(directiveName)) { directiveHandlers.get(directiveName)(directiveName, directiveArgs); } @@ -1878,11 +1878,11 @@ class Parser return; } - if (position < length) + if (position < length) { throwError('end of the stream or a document separator is expected'); - } - else + } + else { return; } @@ -1954,7 +1954,7 @@ class Parser public static inline var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */ - public static var SIMPLE_ESCAPE_SEQUENCES:IntMap = + public static var SIMPLE_ESCAPE_SEQUENCES:IntMap = { var hash = new IntMap(); hash.set(CHAR_DIGIT_ZERO, createUtf8Char(0x00));// '\x00'); @@ -1977,7 +1977,7 @@ class Parser hash.set(CHAR_CAPITAL_P, createUtf8Char(0x2029));//'\u2029'); hash; }; - + static function createUtf8Char(hex:Int):String { var utf8 = new Utf8(1); @@ -1985,7 +1985,7 @@ class Parser return utf8.toString(); } - public static var HEXADECIMAL_ESCAPE_SEQUENCES:IntMap = + public static var HEXADECIMAL_ESCAPE_SEQUENCES:IntMap = { var hash = new IntMap(); hash.set(CHAR_SMALL_X, 2); @@ -1997,7 +1997,7 @@ class Parser #if (neko || cpp || display || php) public static var PATTERN_NON_PRINTABLE = ~/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}-\x{84}\x{86}-\x{9F}\x{FFFE}\x{FFFF}]/u; #elseif (js || flash9 || java) - public static var PATTERN_NON_PRINTABLE = ~/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uD800-\uDFFF\uFFFE\uFFFF]/u; + public static var PATTERN_NON_PRINTABLE = ~/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uD800-\uDFFF\uFFFE\uFFFF]/u; #else #error "Compilation target not supported due to lack of Unicode RegEx support." #end @@ -2009,7 +2009,7 @@ class Parser #else #error "Compilation target not supported due to lack of Unicode RegEx support." #end - + public static var PATTERN_FLOW_INDICATORS = ~/[,\[\]\{\}]/u; public static var PATTERN_TAG_HANDLE = ~/^(?:!|!!|![a-z\-]+!)$/iu; public static var PATTERN_TAG_URI = ~/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/iu; diff --git a/src/yaml/type/YTimestamp.hx b/src/yaml/type/YTimestamp.hx index 280e7c4..964e6bb 100644 --- a/src/yaml/type/YTimestamp.hx +++ b/src/yaml/type/YTimestamp.hx @@ -16,7 +16,7 @@ class YTimestamp extends YamlType '(?:\\.([0-9]*))?' + // [7] fraction '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour '(?::([0-9][0-9]))?))?)?$', "iu"); // [11] tz_minute - + public function new() { super('tag:yaml.org,2002:timestamp', {kind:"string"}, {kind:"object", instanceOf:Date}); @@ -37,7 +37,7 @@ class YTimestamp extends YamlType var fraction:Null = 0; var delta:Null = 0; - try + try { year = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(1)); month = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(2)) - 1; // month starts with 0 @@ -45,7 +45,7 @@ class YTimestamp extends YamlType hour = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(4)); minute = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(5)); second = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(6)); - + // EReg.matched doesn't throw exception under neko for whatever reason so we need to // check for null on each matched call var matched = -1; @@ -55,26 +55,26 @@ class YTimestamp extends YamlType if (hour == null) matched = hour = 0; if (minute == null) matched = minute = 0; if (second == null) matched = second = 0; - + if (matched == 0) throw "Nothing left to match"; var msecs = YAML_TIMESTAMP_REGEXP.matched(7); - if (msecs == null) + if (msecs == null) throw "Nothing left to match"; - + var f = msecs.substring(0, 3); while (f.length < 3) f += '0'; - + fraction = Std.parseInt(f); - + if (YAML_TIMESTAMP_REGEXP.matched(9) != null) { var tz_hour:Null = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(10)); if (tz_hour == null) throw "Nothing left to match"; - + var tz_minute:Null = 0; try { tz_minute = Std.parseInt(YAML_TIMESTAMP_REGEXP.matched(11)); @@ -82,7 +82,7 @@ class YTimestamp extends YamlType tz_minute = 0; } catch(e:Dynamic) {} - + delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds if ('-' == YAML_TIMESTAMP_REGEXP.matched(9)) delta = -delta; @@ -92,15 +92,15 @@ class YTimestamp extends YamlType #if (js || flash) var stamp:Float = nativeDate().UTC(year, month, day, hour, minute, second, fraction); - + if (delta != 0) stamp = stamp - delta; - + return Date.fromTime(stamp); - + #else trace("Warning: UTC dates are not supported under this target"); - + var date = new Date(year, month, day, hour, minute, second); // if (delta != 0) // stamp = stamp - delta; @@ -130,6 +130,6 @@ class YTimestamp extends YamlType trace("Warning: UTC dates are not supported under this target"); return object.toString(); #end - + } } diff --git a/test/TestSuite.hx b/test/TestSuite.hx index f40f0ed..2c55d1c 100644 --- a/test/TestSuite.hx +++ b/test/TestSuite.hx @@ -1,15 +1,15 @@ import massive.munit.TestSuite; -import yaml.type.YPairsTest; -import yaml.type.YIntTest; +import yaml.type.YBinaryTest; import yaml.type.YBoolTest; -import yaml.type.YSetTest; -import yaml.type.YMergeTest; import yaml.type.YFloatTest; +import yaml.type.YIntTest; +import yaml.type.YMergeTest; +import yaml.type.YNullTest; import yaml.type.YOmapTest; +import yaml.type.YPairsTest; +import yaml.type.YSetTest; import yaml.type.YTimestampTest; -import yaml.type.YBinaryTest; -import yaml.type.YNullTest; import yaml.YamlTest; /** @@ -24,16 +24,16 @@ class TestSuite extends massive.munit.TestSuite { super(); - add(yaml.type.YPairsTest); - add(yaml.type.YIntTest); + add(yaml.type.YBinaryTest); add(yaml.type.YBoolTest); - add(yaml.type.YSetTest); - add(yaml.type.YMergeTest); add(yaml.type.YFloatTest); + add(yaml.type.YIntTest); + add(yaml.type.YMergeTest); + add(yaml.type.YNullTest); add(yaml.type.YOmapTest); + add(yaml.type.YPairsTest); + add(yaml.type.YSetTest); add(yaml.type.YTimestampTest); - add(yaml.type.YBinaryTest); - add(yaml.type.YNullTest); add(yaml.YamlTest); } }