Skip to content

Commit

Permalink
Add Support for Changing Letter Case for Props Names
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Aug 2, 2023
1 parent 23da8a4 commit 8b38f4e
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 131 deletions.
11 changes: 11 additions & 0 deletions tests/webfiori/tests/json/JsonConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ public function testToJson11() {
$json->setIsFormatted(false);
$this->assertEquals('{"property-00":1,"property-01":2,"property-02":3}', $json.'');
}
/**
* @test
*/
public function testToJson12() {
$prop = new Property('ABCD', 'world');
$this->assertEquals('"ABCD":"world"', JsonConverter::propertyToJsonString($prop));
$prop->setStyle('snake');
$this->assertEquals('"ABCD":"world"', JsonConverter::propertyToJsonString($prop));
$prop->setStyle('snake', 'lower');
$this->assertEquals('"abcd":"world"', JsonConverter::propertyToJsonString($prop));
}
/**
* @test
*/
Expand Down
73 changes: 54 additions & 19 deletions tests/webfiori/tests/json/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,14 +1139,14 @@ public function testEscJSonSpecialChars02() {
* @test
*/
public function testFormat00() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$this->assertEquals("{\r\n}",$j.'');
}
/**
* @test
*/
public function testFormat01() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addBoolean('hello');
$this->assertEquals("{\r\n"
.' "hello":true'."\r\n"
Expand All @@ -1156,7 +1156,7 @@ public function testFormat01() {
* @test
*/
public function testFormat02() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addNumber('hello',66);
$this->assertEquals("{\r\n"
.' "hello":66'."\r\n"
Expand All @@ -1166,7 +1166,7 @@ public function testFormat02() {
* @test
*/
public function testFormat03() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addString('hello','world');
$j->addString('hello2','another string');
$this->assertEquals("{\r\n"
Expand All @@ -1178,7 +1178,7 @@ public function testFormat03() {
* @test
*/
public function testFormat04() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[]);
$this->assertEquals("{\r\n"
.' "hello-arr":['."\r\n"
Expand All @@ -1189,7 +1189,7 @@ public function testFormat04() {
* @test
*/
public function testFormat05() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[1,2,3,4]);
$this->assertEquals("{\r\n"
.' "hello-arr":['."\r\n"
Expand All @@ -1204,7 +1204,7 @@ public function testFormat05() {
* @test
*/
public function testFormat06() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[[],["hello world"]]);
$this->assertEquals("{\r\n"
.' "hello-arr":['."\r\n"
Expand All @@ -1220,7 +1220,7 @@ public function testFormat06() {
* @test
*/
public function testFormat07() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[[],["hello world",["another sub","with two elements"]]]);
$this->assertEquals("{\r\n"
.' "hello-arr":['."\r\n"
Expand All @@ -1240,7 +1240,7 @@ public function testFormat07() {
* @test
*/
public function testFormat08() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[],true);
$this->assertEquals("{\r\n"
.' "hello-arr":{'."\r\n"
Expand All @@ -1251,7 +1251,7 @@ public function testFormat08() {
* @test
*/
public function testFormat09() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',[1,2,3,"hello mr ali"],true);
$this->assertEquals("{\r\n"
.' "hello-arr":{'."\r\n"
Expand All @@ -1266,7 +1266,7 @@ public function testFormat09() {
* @test
*/
public function testFormat10() {
$j = new Json([],true);
$j = new Json([],null,null,true);
$j->addArray('hello-arr',["is-good" => "You are good",2,3,"hello mr ali",[],["a sub with element","hello" => 'world']],true);
$this->assertEquals("{\r\n"
.' "hello-arr":{'."\r\n"
Expand All @@ -1287,7 +1287,7 @@ public function testFormat10() {
* @test
*/
public function testFormat11() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$obj = new Obj1('Hello',0,true,null,'he');
$j->addObject('object',$obj);
$this->assertEquals('{'."\r\n"
Expand All @@ -1302,7 +1302,7 @@ public function testFormat11() {
* @test
*/
public function testFormat12() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$obj = new Obj1('Hello',0,true,null,'he');
$j->addArray('array',[$obj]);
$this->assertEquals('{'."\r\n"
Expand All @@ -1319,7 +1319,7 @@ public function testFormat12() {
* @test
*/
public function testFormat13() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$obj = new Obj1('Hello',0,true,null,'he');
$j->addArray('array',[$obj],true);
$this->assertEquals('{'."\r\n"
Expand All @@ -1336,7 +1336,7 @@ public function testFormat13() {
* @test
*/
public function testFormat14() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$obj = new Obj1('Hello',0,true,null,'he');
$j->addArray('array',["my-obj" => $obj,"empty-arr" => []],true);
$this->assertEquals('{'."\r\n"
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public function testFormat15() {
'bool' => true,
'number' => 667,
'jsonx' => new Json(['sub-json-x' => new Json()])
],true);
],null,null,true);
$this->assertEquals(''
.'{'."\r\n"
.' "hello":"world",'."\r\n"
Expand All @@ -1390,7 +1390,7 @@ public function testFormat15() {
* @test
*/
public function testFormat16() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$j->addArray('hello-arr',[new Json(),new Json(['hello' => "world"])]);
$this->assertEquals("{\r\n"
.' "hello-arr":['."\r\n"
Expand All @@ -1406,7 +1406,7 @@ public function testFormat16() {
* @test
*/
public function testFormat17() {
$j = new Json([],true);
$j = new Json([], null, null,true);
$j->addArray('Hello_arr',["my-j" => new Json(),new Json(['Hello_x' => "world"])],true);
$this->assertEquals("{\r\n"
.' "Hello_arr":{'."\r\n"
Expand All @@ -1421,6 +1421,41 @@ public function testFormat17() {
$j->setPropsStyle('kebab');
$this->assertEquals(['hello-arr'],$j->getPropsNames());
}
/**
* @test
*/
public function testFormat18() {
$j = new Json([
"hello" => "world",
'object' => new Obj0('8',7,'6','5',4),
'null' => null,
'nan' => NAN,
'inf' => INF,
'bool' => true,
'number' => 667,
'jsonx' => new Json(['sub-json-x' => new Json()])
],null,'upper',true);
$this->assertEquals(''
.'{'."\r\n"
.' "HELLO":"world",'."\r\n"
.' "OBJECT":{'."\r\n"
.' "PROPERTY00":"8",'."\r\n"
.' "PROPERTY01":7,'."\r\n"
.' "PROPERTY02":"6",'."\r\n"
.' "PROPERTY04":4'."\r\n"
.' },'."\r\n"
.' "NULL":null,'."\r\n"
.' "NAN":"NaN",'."\r\n"
.' "INF":"Infinity",'."\r\n"
.' "BOOL":true,'."\r\n"
.' "NUMBER":667,'."\r\n"
.' "JSONX":{'."\r\n"
.' "SUB-JSON-X":{'."\r\n"
.' }'."\r\n"
.' }'."\r\n"
.'}'
.'',$j.'');
}
/**
* @test
*/
Expand Down Expand Up @@ -1573,7 +1608,7 @@ public function testPropCase02() {
* @test
*/
public function testStyle() {
define('JSON_PROP_STYLE','snake');
define('JSON_STYLE','snake');
$json = new Json();
$this->assertEquals('snake',$json->getPropStyle());
}
Expand Down
Loading

0 comments on commit 8b38f4e

Please sign in to comment.