@@ -1864,6 +1864,27 @@ JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) {
1864
1864
JSONTEST_ASSERT (writer.write (nullValue) == " \n " );
1865
1865
}
1866
1866
1867
+ JSONTEST_FIXTURE (WriterTest, enableYAMLCompatibility) {
1868
+ Json::FastWriter writer;
1869
+ Json::Value root;
1870
+ root[" hello" ] = " world" ;
1871
+
1872
+ JSONTEST_ASSERT (writer.write (root) == " {\" hello\" :\" world\" }\n " );
1873
+
1874
+ writer.enableYAMLCompatibility ();
1875
+ JSONTEST_ASSERT (writer.write (root) == " {\" hello\" : \" world\" }\n " );
1876
+ }
1877
+
1878
+ JSONTEST_FIXTURE (WriterTest, omitEndingLineFeed) {
1879
+ Json::FastWriter writer;
1880
+ Json::Value nullValue;
1881
+
1882
+ JSONTEST_ASSERT (writer.write (nullValue) == " null\n " );
1883
+
1884
+ writer.omitEndingLineFeed ();
1885
+ JSONTEST_ASSERT (writer.write (nullValue) == " null" );
1886
+ }
1887
+
1867
1888
struct StreamWriterTest : JsonTest::TestCase {};
1868
1889
1869
1890
JSONTEST_FIXTURE (StreamWriterTest, dropNullPlaceholders) {
@@ -1875,6 +1896,33 @@ JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
1875
1896
JSONTEST_ASSERT (Json::writeString (b, nullValue).empty ());
1876
1897
}
1877
1898
1899
+ JSONTEST_FIXTURE (StreamWriterTest, enableYAMLCompatibility) {
1900
+ Json::StreamWriterBuilder b;
1901
+ Json::Value root;
1902
+ root[" hello" ] = " world" ;
1903
+
1904
+ b.settings_ [" indentation" ] = " " ;
1905
+ JSONTEST_ASSERT (Json::writeString (b, root) == " {\" hello\" :\" world\" }" );
1906
+
1907
+ b.settings_ [" enableYAMLCompatibility" ] = true ;
1908
+ JSONTEST_ASSERT (Json::writeString (b, root) == " {\" hello\" : \" world\" }" );
1909
+
1910
+ b.settings_ [" enableYAMLCompatibility" ] = false ;
1911
+ JSONTEST_ASSERT (Json::writeString (b, root) == " {\" hello\" :\" world\" }" );
1912
+ }
1913
+
1914
+ JSONTEST_FIXTURE (StreamWriterTest, indentation) {
1915
+ Json::StreamWriterBuilder b;
1916
+ Json::Value root;
1917
+ root[" hello" ] = " world" ;
1918
+
1919
+ b.settings_ [" indentation" ] = " " ;
1920
+ JSONTEST_ASSERT (Json::writeString (b, root) == " {\" hello\" :\" world\" }" );
1921
+
1922
+ b.settings_ [" indentation" ] = " \t " ;
1923
+ JSONTEST_ASSERT (Json::writeString (b, root) == " {\n\t\" hello\" : \" world\"\n }" );
1924
+ }
1925
+
1878
1926
JSONTEST_FIXTURE (StreamWriterTest, writeZeroes) {
1879
1927
Json::String binary (" hi" , 3 ); // include trailing 0
1880
1928
JSONTEST_ASSERT_EQUAL (3 , binary.length ());
@@ -2622,7 +2670,11 @@ int main(int argc, const char* argv[]) {
2622
2670
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, precision);
2623
2671
2624
2672
JSONTEST_REGISTER_FIXTURE (runner, WriterTest, dropNullPlaceholders);
2673
+ JSONTEST_REGISTER_FIXTURE (runner, WriterTest, enableYAMLCompatibility);
2674
+ JSONTEST_REGISTER_FIXTURE (runner, WriterTest, omitEndingLineFeed);
2625
2675
JSONTEST_REGISTER_FIXTURE (runner, StreamWriterTest, dropNullPlaceholders);
2676
+ JSONTEST_REGISTER_FIXTURE (runner, StreamWriterTest, enableYAMLCompatibility);
2677
+ JSONTEST_REGISTER_FIXTURE (runner, StreamWriterTest, indentation);
2626
2678
JSONTEST_REGISTER_FIXTURE (runner, StreamWriterTest, writeZeroes);
2627
2679
2628
2680
JSONTEST_REGISTER_FIXTURE (runner, ReaderTest, parseWithNoErrors);
0 commit comments