diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 5550acf162..5c4852d8f4 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -40,7 +40,7 @@ jobs: - golang,schema-golang - cjson,schema-cjson - cjson-default,cjson-multi-header,cjson-multi-split - - cplusplus,schema-cplusplus + - cplusplus,schema-cplusplus,schema-cplusplus-upper-acronyms - flow,schema-flow - java,schema-java - python,schema-python diff --git a/packages/quicktype-core/src/support/Strings.ts b/packages/quicktype-core/src/support/Strings.ts index e9d9a82ed4..080b151e40 100644 --- a/packages/quicktype-core/src/support/Strings.ts +++ b/packages/quicktype-core/src/support/Strings.ts @@ -619,10 +619,13 @@ export function makeNameStyle( switch (namingStyle) { case "pascal": - case "pascal-upper-acronyms": firstWordAcronymStyle = firstUpperWordStyle; firstWordStyle = firstWordAcronymStyle; break; + case "pascal-upper-acronyms": + firstWordStyle = firstUpperWordStyle; + firstWordAcronymStyle = allUpperWordStyle; + break; case "camel": case "camel-upper-acronyms": firstWordAcronymStyle = allLowerWordStyle; diff --git a/test/fixtures.ts b/test/fixtures.ts index 84616537e7..52119b0f45 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -929,6 +929,28 @@ class JSONSchemaFixture extends LanguageFixture { } } +class CPlusPlusUpperAcronymsFixture extends JSONSchemaFixture { + constructor() { + super( + languages.CPlusPlusUpperAcronymsLanguage, + "schema-cplusplus-upper-acronyms", + ); + } + + runForName(name: string): boolean { + return this.name === name; + } + + getSamples(sources: string[]): { priority: Sample[]; others: Sample[] } { + return samplesFromSources( + sources, + ["test/inputs/schema/upper-acronym-names.schema"], + [], + "schema", + ); + } +} + // `leadingComments` is a quicktype-core API option, so the CLI fixture path // cannot exercise it. class LeadingCommentsGoFixture extends JSONSchemaFixture { @@ -1809,6 +1831,7 @@ export const allFixtures: Fixture[] = [ new LeadingCommentsGoFixture(), new JSONSchemaFixture(languages.CJSONLanguage), new JSONSchemaFixture(languages.CPlusPlusLanguage), + new CPlusPlusUpperAcronymsFixture(), new JSONSchemaFixture(languages.RustLanguage), new JSONSchemaFixture(languages.RubyLanguage), new JSONSchemaFixture(languages.PythonLanguage), diff --git a/test/fixtures/cplusplus/acronym_names.cpp b/test/fixtures/cplusplus/acronym_names.cpp new file mode 100644 index 0000000000..613aef98e6 --- /dev/null +++ b/test/fixtures/cplusplus/acronym_names.cpp @@ -0,0 +1,6 @@ +#include "quicktype.hpp" + +void use_upper_acronym_names( + quicktype::SCUBAWaypoint *, + quicktype::SCUBAManeuver *, + quicktype::IDCardHTTP *) {} diff --git a/test/inputs/schema/upper-acronym-names.1.fail.enum.json b/test/inputs/schema/upper-acronym-names.1.fail.enum.json new file mode 100644 index 0000000000..711ae90282 --- /dev/null +++ b/test/inputs/schema/upper-acronym-names.1.fail.enum.json @@ -0,0 +1,15 @@ +{ + "waypoints": [ + { + "location": { + "latitude": 43.0, + "longitude": 16.0 + }, + "depth": 12.5, + "maneuver": "BACKFLIP", + "idCard": { + "value": "HTTP" + } + } + ] +} diff --git a/test/inputs/schema/upper-acronym-names.1.json b/test/inputs/schema/upper-acronym-names.1.json new file mode 100644 index 0000000000..52372eed94 --- /dev/null +++ b/test/inputs/schema/upper-acronym-names.1.json @@ -0,0 +1,15 @@ +{ + "waypoints": [ + { + "location": { + "latitude": 43.0, + "longitude": 16.0 + }, + "depth": 12.5, + "maneuver": "LEVEL", + "idCard": { + "value": "HTTP" + } + } + ] +} diff --git a/test/inputs/schema/upper-acronym-names.schema b/test/inputs/schema/upper-acronym-names.schema new file mode 100644 index 0000000000..03210c4557 --- /dev/null +++ b/test/inputs/schema/upper-acronym-names.schema @@ -0,0 +1,37 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "description": "A SCUBA dive log with waypoints", + "type": "object", + "properties": { + "waypoints": { + "type": "array", + "items": { + "title": "SCUBAWaypoint", + "type": "object", + "properties": { + "location": { + "title": "Point", + "type": "object", + "properties": { + "latitude": { "type": "number" }, + "longitude": { "type": "number" } + } + }, + "depth": { "type": "number" }, + "maneuver": { + "title": "SCUBAManeuver", + "type": "string", + "enum": ["ASCENT", "DESCENT", "LEVEL"] + }, + "idCard": { + "title": "IDCardHTTP", + "type": "object", + "properties": { + "value": { "type": "string" } + } + } + } + } + } + } +} diff --git a/test/languages.ts b/test/languages.ts index 120f3170b0..a39e958069 100644 --- a/test/languages.ts +++ b/test/languages.ts @@ -25,6 +25,7 @@ const skipsEnumValueValidation = [ "enum-large.schema", "optional-enum.schema", "const-non-string.schema", + "upper-acronym-names.schema", "haskell-enum-forbidden.schema", "nullable-optional-one-of.schema", "all-of-additional-properties-false.schema", @@ -854,6 +855,16 @@ export const CPlusPlusLanguage: Language = { sourceFiles: ["src/language/CPlusPlus/index.ts"], }; +export const CPlusPlusUpperAcronymsLanguage: Language = { + ...CPlusPlusLanguage, + compileCommand: + "g++ -O0 -o quicktype -std=c++17 main.cpp acronym_names.cpp", + rendererOptions: { + "type-style": "pascal-case-upper-acronyms", + "member-style": "camel-case-upper-acronyms", + }, +}; + export const CPlusPlusMultiSourceLanguage: Language = { ...CPlusPlusLanguage, includeJSON: ["pokedex.json"],