-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
b9483e7
commit fa9d2c9
Showing
19 changed files
with
695 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you 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. | ||
|
||
import ballerina/test; | ||
|
||
@test:Config { | ||
groups: ["prettify", "string"] | ||
} | ||
function testStringValue() returns error? { | ||
json value = "Sam"; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("string_value.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "int"] | ||
} | ||
function testIntValue() returns error? { | ||
json value = 515; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("int_value.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "boolean"] | ||
} | ||
function testBooleanValue() returns error? { | ||
json value = false; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("boolean_value.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "null"] | ||
} | ||
function testNullValue() returns error? { | ||
json value = null; | ||
string actual = prettify(value); | ||
string expected = " null"; | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "array"] | ||
} | ||
function testStringArray() returns error? { | ||
json value = ["sam", "bam", "tan"]; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("string_array.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "array"] | ||
} | ||
function testEmptyArray() returns error? { | ||
json value = []; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("empty_array.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testEmptyMap() returns error? { | ||
json value = {}; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("empty_map.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testArrayOfEmptyMaps() returns error? { | ||
json value = [ | ||
{}, | ||
{}, | ||
{} | ||
]; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("array_of_empty_maps.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testMapWithStringField() returns error? { | ||
json value = { | ||
name: "Walter White" | ||
}; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("map_with_string_field.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testMapWithMultipleStringFields() returns error? { | ||
json value = { | ||
name: "Walter White", | ||
subject: "Chemistry", | ||
city: "Albequerque" | ||
}; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("map_with_multiple_string_fields.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testMap() returns error? { | ||
json value = { | ||
person: { | ||
name: "Walter White", | ||
age: 51, | ||
address: { | ||
number: 308, | ||
street: "Negra Arroyo Lane", | ||
city: "Albequerque" | ||
} | ||
} | ||
}; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("map.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "map"] | ||
} | ||
function testArrayOfMap() returns error? { | ||
json value = [ | ||
{ | ||
name: "Walter White", | ||
age: 51, | ||
address: { | ||
number: 308, | ||
street: "Negra Arroyo Lane", | ||
city: "Albequerque" | ||
} | ||
}, | ||
{ | ||
name: "Jesse Pinkman", | ||
age: 26, | ||
address: { | ||
number: 9809, | ||
street: "Margo Street", | ||
city: "Albequerque" | ||
} | ||
} | ||
]; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("array_of_map.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "array", "map"] | ||
} | ||
function testComplexExample() returns error? { | ||
json value = check getJsonContentFromFile("complex_example.json"); | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("complex_example.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "array", "map"] | ||
} | ||
function testComplexExampleWithCustomIndentation() returns error? { | ||
json value = check getJsonContentFromFile("complex_example.json"); | ||
string actual = prettify(value, 2); | ||
string expected = check getStringContentFromFile("complex_example_with_custom_indentation.json"); | ||
test:assertEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "array", "map"] | ||
} | ||
function testComplexExampleWithCustomIndentationInvalidTest() returns error? { | ||
json value = check getJsonContentFromFile("complex_example.json"); | ||
string actual = prettify(value, 2); | ||
string expected = check getStringContentFromFile("complex_example.json"); | ||
test:assertNotEquals(actual, expected); | ||
} | ||
|
||
@test:Config { | ||
groups: ["prettify", "null"] | ||
} | ||
function testJsonValueWithNull() returns error? { | ||
json value = { | ||
name: "Walter White", | ||
age: null, | ||
address: { | ||
number: 308, | ||
street: (), | ||
city: "Albequerque" | ||
} | ||
}; | ||
string actual = prettify(value); | ||
string expected = check getStringContentFromFile("json_value_with_null.json"); | ||
test:assertEquals(actual, expected); | ||
} |
5 changes: 5 additions & 0 deletions
5
ballerina/tests/resources/expected_results/array_of_empty_maps.json
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,5 @@ | ||
[ | ||
{}, | ||
{}, | ||
{} | ||
] |
20 changes: 20 additions & 0 deletions
20
ballerina/tests/resources/expected_results/array_of_map.json
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,20 @@ | ||
[ | ||
{ | ||
"name": "Walter White", | ||
"age": 51, | ||
"address": { | ||
"number": 308, | ||
"street": "Negra Arroyo Lane", | ||
"city": "Albequerque" | ||
} | ||
}, | ||
{ | ||
"name": "Jesse Pinkman", | ||
"age": 26, | ||
"address": { | ||
"number": 9809, | ||
"street": "Margo Street", | ||
"city": "Albequerque" | ||
} | ||
} | ||
] |
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 @@ | ||
false |
87 changes: 87 additions & 0 deletions
87
ballerina/tests/resources/expected_results/complex_example.json
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,87 @@ | ||
{ | ||
"colors": [ | ||
{ | ||
"color": "black", | ||
"category": "hue", | ||
"type": "primary", | ||
"code": { | ||
"rgba": [ | ||
255, | ||
255, | ||
255, | ||
1 | ||
], | ||
"hex": "#000" | ||
} | ||
}, | ||
{ | ||
"color": "white", | ||
"category": "value", | ||
"code": { | ||
"rgba": [ | ||
0, | ||
0, | ||
0, | ||
1 | ||
], | ||
"hex": "#FFF" | ||
} | ||
}, | ||
{ | ||
"color": "red", | ||
"category": "hue", | ||
"type": "primary", | ||
"code": { | ||
"rgba": [ | ||
255, | ||
0, | ||
0, | ||
1 | ||
], | ||
"hex": "#FF0" | ||
} | ||
}, | ||
{ | ||
"color": "blue", | ||
"category": "hue", | ||
"type": "primary", | ||
"code": { | ||
"rgba": [ | ||
0, | ||
0, | ||
255, | ||
1 | ||
], | ||
"hex": "#00F" | ||
} | ||
}, | ||
{ | ||
"color": "yellow", | ||
"category": "hue", | ||
"type": "primary", | ||
"code": { | ||
"rgba": [ | ||
255, | ||
255, | ||
0, | ||
1 | ||
], | ||
"hex": "#FF0" | ||
} | ||
}, | ||
{ | ||
"color": "green", | ||
"category": "hue", | ||
"type": "secondary", | ||
"code": { | ||
"rgba": [ | ||
0, | ||
255, | ||
0, | ||
1 | ||
], | ||
"hex": "#0F0" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.