================ @@ -171,5 +171,78 @@ TEST(JSONGeneratorTest, emitRecordJSON) { })raw"; EXPECT_EQ(Expected, Actual.str()); } + +TEST(JSONGeneratorTest, emitNamespaceJSON) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Path = "path/to/A"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.Children.Namespaces.emplace_back( + EmptySID, "ChildNamespace", InfoType::IT_namespace, + "path::to::A::Namespace::ChildNamespace", "path/to/A/Namespace"); + I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record, + "path::to::A::Namespace::ChildStruct", + "path/to/A/Namespace"); + I.Children.Functions.emplace_back(); + I.Children.Functions.back().Name = "OneFunction"; + I.Children.Functions.back().Access = AccessSpecifier::AS_none; + I.Children.Enums.emplace_back(); + I.Children.Enums.back().Name = "OneEnum"; + + auto G = getJSONGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext()); + assert(!Err); + std::string Expected = R"raw({ + "Enums": [ + { + "Name": "OneEnum", + "Scoped": false, + "USR": "0000000000000000000000000000000000000000" + } + ], + "Functions": [ + { + "IsStatic": false, + "Name": "OneFunction", + "ReturnType": { + "IsBuiltIn": false, + "IsTemplate": false, + "Name": "", + "QualName": "", + "USR": "0000000000000000000000000000000000000000" + }, + "USR": "0000000000000000000000000000000000000000" + } + ], + "Name": "Namespace", + "Namespace": [ + "A" + ], + "NamespacePath": "path/to/A/Namespace", ---------------- ilovepi wrote:
``` C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-doc\json\class.cpp:166:16: error: CHECK-NEXT: expected string not found in input # | // CHECK-NEXT: "Path": "GlobalNamespace/MyClass", # | ^ # | <stdin>:169:24: note: scanning from here # | "Name": "NestedClass", # | ^ # | <stdin>:170:2: note: possible intended match here # | "Path": "GlobalNamespace\\MyClass", # | ^ ``` >From the bot, it looks like its not. Depending on how you expect that field to >be used, I could see you go one of two ways. 1. You want to use the path as a real filesystem path, in which case, you'd update the test to check for either separator. 2. It's more an abstract/logical distinction, and you intend to use it similar to a URL, in which case you can always make it POSIX style. https://github.com/llvm/llvm-project/pull/143209 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits