This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
raml-parser-2/src/test/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2013 (c) MuleSoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
package org.raml.yagi.framework.grammar.rule; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.raml.yagi.framework.nodes.BooleanNode; | ||
import org.raml.yagi.framework.nodes.StringNodeImpl; | ||
import org.raml.yagi.framework.nodes.jackson.JBooleanNode; | ||
import org.raml.yagi.framework.nodes.snakeyaml.SYBooleanNode; | ||
import org.raml.yagi.framework.nodes.snakeyaml.SYStringNode; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Created. There, you have it. | ||
*/ | ||
public class BooleanTypeRuleTest | ||
{ | ||
|
||
@Test | ||
public void booleanWillMatchString() | ||
{ | ||
|
||
BooleanTypeRule rule = new BooleanTypeRule(true); | ||
assertFalse(rule.matches(new StringNodeImpl("false"))); | ||
assertFalse(rule.matches(new StringNodeImpl("true"))); | ||
assertFalse(rule.matches(new StringNodeImpl("anythingElse"))); | ||
} | ||
|
||
@Test | ||
public void booleanWontMatchString() | ||
{ | ||
|
||
BooleanTypeRule rule = new BooleanTypeRule(false); | ||
assertTrue(rule.matches(new StringNodeImpl("false"))); | ||
assertTrue(rule.matches(new StringNodeImpl("true"))); | ||
assertFalse(rule.matches(new StringNodeImpl("anythingElse"))); | ||
} | ||
|
||
@Test | ||
public void booleanMatchesBoolean() | ||
{ | ||
|
||
BooleanNode booleanNode = Mockito.mock(BooleanNode.class); | ||
BooleanTypeRule rule = new BooleanTypeRule(true); | ||
assertTrue(rule.matches(booleanNode)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/input.raml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#%RAML 1.0 | ||
title: Sample API | ||
types: | ||
TestType: | ||
type: object | ||
properties: | ||
count?: integer | ||
flag?: boolean | ||
name?: string | ||
/test: | ||
post: | ||
body: | ||
application/json: | ||
type: TestType | ||
example: | | ||
{ "count": 12, "flag": "true", "name": "Joe" } |
97 changes: 97 additions & 0 deletions
97
raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
RamlDocumentNode (Start: 11 , End: 291, On: input.raml, Source: SYObjectNode) | ||
KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml) | ||
SYStringNode: "title" (Start: 11 , End: 16, On: input.raml) | ||
OverlayableObjectNodeImpl (Start: 18 , End: 28, On: input.raml, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "Sample API" (Start: 18 , End: 28, On: input.raml) | ||
TypesNode (Start: 29 , End: 144, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "types" (Start: 29 , End: 34, On: input.raml) | ||
SYObjectNode (Start: 38 , End: 144, On: input.raml) | ||
TypeDeclarationField (Start: 38 , End: 144, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "TestType" (Start: 38 , End: 46, On: input.raml) | ||
TypeDeclarationNode (Start: 52 , End: 144, On: input.raml, Source: SYObjectNode) | ||
KeyValueNodeImpl (Start: 52 , End: 64, On: input.raml) | ||
SYStringNode: "type" (Start: 52 , End: 56, On: input.raml) | ||
NativeTypeExpressionNode: "object" (Start: 58 , End: 64, On: input.raml, Source: SYStringNode) | ||
FacetNode (Start: 69 , End: 144, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "properties" (Start: 69 , End: 79, On: input.raml) | ||
SYObjectNode (Start: 87 , End: 144, On: input.raml) | ||
PropertyNode (Start: 87 , End: 102, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "count?" (Start: 87 , End: 93, On: input.raml) | ||
TypeDeclarationNode (Start: 95 , End: 102, On: input.raml, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: 102) | ||
StringNodeImpl: "type" (Start: -1 , End: -1) | ||
NativeTypeExpressionNode: "integer" (Start: 95 , End: 102, On: input.raml, Source: NativeTypeExpressionNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "count?" (Start: -1 , End: -1, Source: SYStringNode) | ||
PropertyNode (Start: 109 , End: 123, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "flag?" (Start: 109 , End: 114, On: input.raml) | ||
TypeDeclarationNode (Start: 116 , End: 123, On: input.raml, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: 123) | ||
StringNodeImpl: "type" (Start: -1 , End: -1) | ||
NativeTypeExpressionNode: "boolean" (Start: 116 , End: 123, On: input.raml, Source: NativeTypeExpressionNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "flag?" (Start: -1 , End: -1, Source: SYStringNode) | ||
PropertyNode (Start: 130 , End: 143, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "name?" (Start: 130 , End: 135, On: input.raml) | ||
TypeDeclarationNode (Start: 137 , End: 143, On: input.raml, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: 143) | ||
StringNodeImpl: "type" (Start: -1 , End: -1) | ||
NativeTypeExpressionNode: "string" (Start: 137 , End: 143, On: input.raml, Source: NativeTypeExpressionNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "name?" (Start: -1 , End: -1, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "TestType" (Start: -1 , End: -1, Source: SYStringNode) | ||
ResourceNode (Start: 144 , End: 291, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "/test" (Start: 144 , End: 149, On: input.raml) | ||
SYObjectNode (Start: 153 , End: 291, On: input.raml) | ||
MethodNode (Start: 153 , End: 291, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "post" (Start: 153 , End: 157, On: input.raml) | ||
SYObjectNode (Start: 163 , End: 291, On: input.raml) | ||
BodyNode (Start: 163 , End: 291, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "body" (Start: 163 , End: 167, On: input.raml) | ||
SYObjectNode (Start: 175 , End: 291, On: input.raml) | ||
KeyValueNodeImpl (Start: 175 , End: 291, On: input.raml) | ||
SYStringNode: "application/json" (Start: 175 , End: 191, On: input.raml) | ||
TypeDeclarationNode (Start: 201 , End: 291, On: input.raml, Source: SYObjectNode) | ||
KeyValueNodeImpl (Start: 201 , End: 215, On: input.raml) | ||
SYStringNode: "type" (Start: 201 , End: 205, On: input.raml) | ||
NamedTypeExpressionNode TestType -> {TypeDeclarationNode RefStart: 52 , RefEnd: 144} (Start: 207 , End: 215, On: input.raml, Source: SYStringNode) | ||
ExampleDeclarationNode (Start: 224 , End: 291, On: input.raml, Source: KeyValueNodeImpl) | ||
SYStringNode: "example" (Start: 224 , End: 231, On: input.raml) | ||
SYStringNode: "{ "count": 12, "flag": "true", "name": "Joe" }" (Start: 233 , End: 291, On: input.raml) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "application/json" (Start: -1 , End: -1, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "post" (Start: -1 , End: -1, Source: SYStringNode) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "displayName" (Start: -1 , End: -1) | ||
ObjectNodeImpl (Start: -1 , End: -1) | ||
KeyValueNodeImpl (Start: -1 , End: -1) | ||
StringNodeImpl: "value" (Start: -1 , End: -1) | ||
OverlayableStringNode: "/test" (Start: -1 , End: -1, Source: SYStringNode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters