Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 9f0fc1b

Browse files
committed
Missing a strict function test.
1 parent a17ea51 commit 9f0fc1b

File tree

7 files changed

+194
-4
lines changed

7 files changed

+194
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.raml</groupId>
44
<artifactId>raml-parser-parent</artifactId>
5-
<version>1.0.46-SNAPSHOT</version>
5+
<version>1.0.48-SNAPSHOT</version>
66
<packaging>pom</packaging>
77
<name>Raml Java Parser 2nd generation parent</name>
88
<description>Raml parser implemented in java</description>

raml-parser-2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.raml</groupId>
55
<artifactId>raml-parser-parent</artifactId>
6-
<version>1.0.46-SNAPSHOT</version>
6+
<version>1.0.48-SNAPSHOT</version>
77
</parent>
88
<artifactId>raml-parser-2</artifactId>
99
<packaging>jar</packaging>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2013 (c) MuleSoft, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an
12+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific
14+
* language governing permissions and limitations under the License.
15+
*/
16+
package org.raml.yagi.framework.grammar.rule;
17+
18+
import org.junit.Test;
19+
import org.mockito.Mockito;
20+
import org.raml.yagi.framework.nodes.BooleanNode;
21+
import org.raml.yagi.framework.nodes.StringNodeImpl;
22+
import org.raml.yagi.framework.nodes.jackson.JBooleanNode;
23+
import org.raml.yagi.framework.nodes.snakeyaml.SYBooleanNode;
24+
import org.raml.yagi.framework.nodes.snakeyaml.SYStringNode;
25+
26+
import static org.junit.Assert.*;
27+
28+
/**
29+
* Created. There, you have it.
30+
*/
31+
public class BooleanTypeRuleTest
32+
{
33+
34+
@Test
35+
public void booleanWillMatchString()
36+
{
37+
38+
BooleanTypeRule rule = new BooleanTypeRule(true);
39+
assertFalse(rule.matches(new StringNodeImpl("false")));
40+
assertFalse(rule.matches(new StringNodeImpl("true")));
41+
assertFalse(rule.matches(new StringNodeImpl("anythingElse")));
42+
}
43+
44+
@Test
45+
public void booleanWontMatchString()
46+
{
47+
48+
BooleanTypeRule rule = new BooleanTypeRule(false);
49+
assertTrue(rule.matches(new StringNodeImpl("false")));
50+
assertTrue(rule.matches(new StringNodeImpl("true")));
51+
assertFalse(rule.matches(new StringNodeImpl("anythingElse")));
52+
}
53+
54+
@Test
55+
public void booleanMatchesBoolean()
56+
{
57+
58+
BooleanNode booleanNode = Mockito.mock(BooleanNode.class);
59+
BooleanTypeRule rule = new BooleanTypeRule(true);
60+
assertTrue(rule.matches(booleanNode));
61+
}
62+
63+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#%RAML 1.0
2+
title: Sample API
3+
types:
4+
TestType:
5+
type: object
6+
properties:
7+
count?: integer
8+
flag?: boolean
9+
name?: string
10+
/test:
11+
post:
12+
body:
13+
application/json:
14+
type: TestType
15+
example: |
16+
{ "count": 12, "flag": "true", "name": "Joe" }
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
RamlDocumentNode (Start: 11 , End: 291, On: input.raml, Source: SYObjectNode)
2+
KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml)
3+
SYStringNode: "title" (Start: 11 , End: 16, On: input.raml)
4+
OverlayableObjectNodeImpl (Start: 18 , End: 28, On: input.raml, Source: SYStringNode)
5+
KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml)
6+
StringNodeImpl: "value" (Start: -1 , End: -1)
7+
OverlayableStringNode: "Sample API" (Start: 18 , End: 28, On: input.raml)
8+
TypesNode (Start: 29 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
9+
SYStringNode: "types" (Start: 29 , End: 34, On: input.raml)
10+
SYObjectNode (Start: 38 , End: 144, On: input.raml)
11+
TypeDeclarationField (Start: 38 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
12+
SYStringNode: "TestType" (Start: 38 , End: 46, On: input.raml)
13+
TypeDeclarationNode (Start: 52 , End: 144, On: input.raml, Source: SYObjectNode)
14+
KeyValueNodeImpl (Start: 52 , End: 64, On: input.raml)
15+
SYStringNode: "type" (Start: 52 , End: 56, On: input.raml)
16+
NativeTypeExpressionNode: "object" (Start: 58 , End: 64, On: input.raml, Source: SYStringNode)
17+
FacetNode (Start: 69 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
18+
SYStringNode: "properties" (Start: 69 , End: 79, On: input.raml)
19+
SYObjectNode (Start: 87 , End: 144, On: input.raml)
20+
PropertyNode (Start: 87 , End: 102, On: input.raml, Source: KeyValueNodeImpl)
21+
SYStringNode: "count?" (Start: 87 , End: 93, On: input.raml)
22+
TypeDeclarationNode (Start: 95 , End: 102, On: input.raml, Source: SYStringNode)
23+
KeyValueNodeImpl (Start: -1 , End: 102)
24+
StringNodeImpl: "type" (Start: -1 , End: -1)
25+
NativeTypeExpressionNode: "integer" (Start: 95 , End: 102, On: input.raml, Source: NativeTypeExpressionNode)
26+
KeyValueNodeImpl (Start: -1 , End: -1)
27+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
28+
ObjectNodeImpl (Start: -1 , End: -1)
29+
KeyValueNodeImpl (Start: -1 , End: -1)
30+
StringNodeImpl: "value" (Start: -1 , End: -1)
31+
OverlayableStringNode: "count?" (Start: -1 , End: -1, Source: SYStringNode)
32+
PropertyNode (Start: 109 , End: 123, On: input.raml, Source: KeyValueNodeImpl)
33+
SYStringNode: "flag?" (Start: 109 , End: 114, On: input.raml)
34+
TypeDeclarationNode (Start: 116 , End: 123, On: input.raml, Source: SYStringNode)
35+
KeyValueNodeImpl (Start: -1 , End: 123)
36+
StringNodeImpl: "type" (Start: -1 , End: -1)
37+
NativeTypeExpressionNode: "boolean" (Start: 116 , End: 123, On: input.raml, Source: NativeTypeExpressionNode)
38+
KeyValueNodeImpl (Start: -1 , End: -1)
39+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
40+
ObjectNodeImpl (Start: -1 , End: -1)
41+
KeyValueNodeImpl (Start: -1 , End: -1)
42+
StringNodeImpl: "value" (Start: -1 , End: -1)
43+
OverlayableStringNode: "flag?" (Start: -1 , End: -1, Source: SYStringNode)
44+
PropertyNode (Start: 130 , End: 143, On: input.raml, Source: KeyValueNodeImpl)
45+
SYStringNode: "name?" (Start: 130 , End: 135, On: input.raml)
46+
TypeDeclarationNode (Start: 137 , End: 143, On: input.raml, Source: SYStringNode)
47+
KeyValueNodeImpl (Start: -1 , End: 143)
48+
StringNodeImpl: "type" (Start: -1 , End: -1)
49+
NativeTypeExpressionNode: "string" (Start: 137 , End: 143, On: input.raml, Source: NativeTypeExpressionNode)
50+
KeyValueNodeImpl (Start: -1 , End: -1)
51+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
52+
ObjectNodeImpl (Start: -1 , End: -1)
53+
KeyValueNodeImpl (Start: -1 , End: -1)
54+
StringNodeImpl: "value" (Start: -1 , End: -1)
55+
OverlayableStringNode: "name?" (Start: -1 , End: -1, Source: SYStringNode)
56+
KeyValueNodeImpl (Start: -1 , End: -1)
57+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
58+
ObjectNodeImpl (Start: -1 , End: -1)
59+
KeyValueNodeImpl (Start: -1 , End: -1)
60+
StringNodeImpl: "value" (Start: -1 , End: -1)
61+
OverlayableStringNode: "TestType" (Start: -1 , End: -1, Source: SYStringNode)
62+
ResourceNode (Start: 144 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
63+
SYStringNode: "/test" (Start: 144 , End: 149, On: input.raml)
64+
SYObjectNode (Start: 153 , End: 291, On: input.raml)
65+
MethodNode (Start: 153 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
66+
SYStringNode: "post" (Start: 153 , End: 157, On: input.raml)
67+
SYObjectNode (Start: 163 , End: 291, On: input.raml)
68+
BodyNode (Start: 163 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
69+
SYStringNode: "body" (Start: 163 , End: 167, On: input.raml)
70+
SYObjectNode (Start: 175 , End: 291, On: input.raml)
71+
KeyValueNodeImpl (Start: 175 , End: 291, On: input.raml)
72+
SYStringNode: "application/json" (Start: 175 , End: 191, On: input.raml)
73+
TypeDeclarationNode (Start: 201 , End: 291, On: input.raml, Source: SYObjectNode)
74+
KeyValueNodeImpl (Start: 201 , End: 215, On: input.raml)
75+
SYStringNode: "type" (Start: 201 , End: 205, On: input.raml)
76+
NamedTypeExpressionNode TestType -> {TypeDeclarationNode RefStart: 52 , RefEnd: 144} (Start: 207 , End: 215, On: input.raml, Source: SYStringNode)
77+
ExampleDeclarationNode (Start: 224 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
78+
SYStringNode: "example" (Start: 224 , End: 231, On: input.raml)
79+
SYStringNode: "{ "count": 12, "flag": "true", "name": "Joe" }" (Start: 233 , End: 291, On: input.raml)
80+
KeyValueNodeImpl (Start: -1 , End: -1)
81+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
82+
ObjectNodeImpl (Start: -1 , End: -1)
83+
KeyValueNodeImpl (Start: -1 , End: -1)
84+
StringNodeImpl: "value" (Start: -1 , End: -1)
85+
OverlayableStringNode: "application/json" (Start: -1 , End: -1, Source: SYStringNode)
86+
KeyValueNodeImpl (Start: -1 , End: -1)
87+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
88+
ObjectNodeImpl (Start: -1 , End: -1)
89+
KeyValueNodeImpl (Start: -1 , End: -1)
90+
StringNodeImpl: "value" (Start: -1 , End: -1)
91+
OverlayableStringNode: "post" (Start: -1 , End: -1, Source: SYStringNode)
92+
KeyValueNodeImpl (Start: -1 , End: -1)
93+
StringNodeImpl: "displayName" (Start: -1 , End: -1)
94+
ObjectNodeImpl (Start: -1 , End: -1)
95+
KeyValueNodeImpl (Start: -1 , End: -1)
96+
StringNodeImpl: "value" (Start: -1 , End: -1)
97+
OverlayableStringNode: "/test" (Start: -1 , End: -1, Source: SYStringNode)

yagi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.raml</groupId>
55
<artifactId>raml-parser-parent</artifactId>
6-
<version>1.0.46-SNAPSHOT</version>
6+
<version>1.0.48-SNAPSHOT</version>
77
</parent>
88
<artifactId>yagi</artifactId>
99
<packaging>jar</packaging>

yagi/src/main/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRule.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,23 @@
2929

3030
public class BooleanTypeRule extends AbstractTypeRule
3131
{
32+
private static final String STRICT_BOOLEANS = "org.raml.strict_booleans";
33+
3234
private final static String TRUE = "true";
3335
private final static String FALSE = "false";
3436

37+
private final boolean strictBoolean;
38+
39+
public BooleanTypeRule()
40+
{
41+
this.strictBoolean = Boolean.parseBoolean(System.getProperty(STRICT_BOOLEANS, "false"));
42+
}
43+
44+
BooleanTypeRule(boolean strictBoolean)
45+
{
46+
this.strictBoolean = strictBoolean;
47+
}
48+
3549
@Nonnull
3650
@Override
3751
public List<Suggestion> getSuggestions(Node node, ParsingContext context)
@@ -42,7 +56,7 @@ public List<Suggestion> getSuggestions(Node node, ParsingContext context)
4256
@Override
4357
public boolean matches(@Nonnull Node node)
4458
{
45-
if (node instanceof StringNode)
59+
if (!strictBoolean && (node instanceof StringNode))
4660
{
4761
String value = ((StringNode) node).getValue();
4862
return TRUE.equals(value) || FALSE.equals(value);

0 commit comments

Comments
 (0)