@@ -1843,6 +1843,109 @@ TEST(AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_5) {
1843
1843
EXPECT_EQ (document, expected);
1844
1844
}
1845
1845
1846
+ TEST (AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_6) {
1847
+ sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
1848
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1849
+ "allOf": [
1850
+ { "$ref": "https://example.com" }
1851
+ ],
1852
+ "title": "Foo"
1853
+ })JSON" );
1854
+
1855
+ LINT_AND_FIX_FOR_READABILITY (document);
1856
+
1857
+ const sourcemeta::core::JSON expected = sourcemeta::core::parse_json (R"JSON( {
1858
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1859
+ "$ref": "https://example.com",
1860
+ "title": "Foo"
1861
+ })JSON" );
1862
+
1863
+ EXPECT_EQ (document, expected);
1864
+
1865
+ // We expect the `$ref` keyword to take the place of `allOf` in
1866
+ // terms of keyword ordering
1867
+ std::vector<sourcemeta::core::JSON::String> keywords;
1868
+ for (const auto &entry : document.as_object ()) {
1869
+ keywords.emplace_back (entry.first );
1870
+ }
1871
+
1872
+ EXPECT_EQ (keywords.size (), 3 );
1873
+ EXPECT_EQ (keywords.at (0 ), " $schema" );
1874
+ EXPECT_EQ (keywords.at (1 ), " $ref" );
1875
+ EXPECT_EQ (keywords.at (2 ), " title" );
1876
+ }
1877
+
1878
+ TEST (AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_7) {
1879
+ sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
1880
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1881
+ "allOf": [
1882
+ { "$ref": "https://example.com" },
1883
+ { "type": "string" }
1884
+ ],
1885
+ "title": "Foo"
1886
+ })JSON" );
1887
+
1888
+ LINT_AND_FIX_FOR_READABILITY (document);
1889
+
1890
+ const sourcemeta::core::JSON expected = sourcemeta::core::parse_json (R"JSON( {
1891
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1892
+ "$ref": "https://example.com",
1893
+ "allOf": [
1894
+ { "type": "string" }
1895
+ ],
1896
+ "title": "Foo"
1897
+ })JSON" );
1898
+
1899
+ EXPECT_EQ (document, expected);
1900
+
1901
+ // We expect the `$ref` keyword to take the place of `allOf` in
1902
+ // terms of keyword ordering
1903
+ std::vector<sourcemeta::core::JSON::String> keywords;
1904
+ for (const auto &entry : document.as_object ()) {
1905
+ keywords.emplace_back (entry.first );
1906
+ }
1907
+
1908
+ EXPECT_EQ (keywords.size (), 4 );
1909
+ EXPECT_EQ (keywords.at (0 ), " $schema" );
1910
+ EXPECT_EQ (keywords.at (1 ), " $ref" );
1911
+ EXPECT_EQ (keywords.at (2 ), " allOf" );
1912
+ EXPECT_EQ (keywords.at (3 ), " title" );
1913
+ }
1914
+
1915
+ TEST (AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_8) {
1916
+ sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
1917
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1918
+ "allOf": [
1919
+ { "type": "string", "$ref": "https://example.com" }
1920
+ ],
1921
+ "title": "Foo"
1922
+ })JSON" );
1923
+
1924
+ LINT_AND_FIX_FOR_READABILITY (document);
1925
+
1926
+ const sourcemeta::core::JSON expected = sourcemeta::core::parse_json (R"JSON( {
1927
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1928
+ "$ref": "https://example.com",
1929
+ "allOf": [ { "type": "string" } ],
1930
+ "title": "Foo"
1931
+ })JSON" );
1932
+
1933
+ EXPECT_EQ (document, expected);
1934
+
1935
+ // We expect the `$ref` keyword to take the place of `allOf` in
1936
+ // terms of keyword ordering
1937
+ std::vector<sourcemeta::core::JSON::String> keywords;
1938
+ for (const auto &entry : document.as_object ()) {
1939
+ keywords.emplace_back (entry.first );
1940
+ }
1941
+
1942
+ EXPECT_EQ (keywords.size (), 4 );
1943
+ EXPECT_EQ (keywords.at (0 ), " $schema" );
1944
+ EXPECT_EQ (keywords.at (1 ), " $ref" );
1945
+ EXPECT_EQ (keywords.at (2 ), " allOf" );
1946
+ EXPECT_EQ (keywords.at (3 ), " title" );
1947
+ }
1948
+
1846
1949
TEST (AlterSchema_lint_2020_12, multiple_of_default_1) {
1847
1950
sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
1848
1951
"$schema": "https://json-schema.org/draft/2020-12/schema",
0 commit comments