Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
compiler_module_name_diagnostics_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
36#include <gtest/gtest.h>
37
39
40using namespace Aleph;
41
43{
45 const auto file = sm.add_virtual_file("main.aw", "let answer = add(1, 2);\n");
46 Diagnostic_Engine diagnostics(sm);
47
49 resolution.status = Compiler_Module_Name_Resolution_Status::Missing_Name;
50 resolution.module_name = "main.aw";
51 resolution.symbol_name = "add";
52 resolution.filter = Compiler_Module_Name_Filter::Function;
53
55 diagnostics, sm.span(file, 13, 16), resolution, "SDK001", "test callee");
56 EXPECT_EQ(index, 0u);
57 ASSERT_EQ(diagnostics.size(), 1u);
58
59 std::ostringstream out;
60 diagnostics.render_plain(out);
61 EXPECT_NE(out.str().find("error[SDK001]: unknown test callee 'add'"), std::string::npos);
62 EXPECT_NE(out.str().find("does not expose that name"), std::string::npos);
63}
64
66{
68 const auto file = sm.add_virtual_file("main.aw", "let answer = add(1, 2);\n");
69 Diagnostic_Engine diagnostics(sm);
70
72 resolution.status = Compiler_Module_Name_Resolution_Status::Wrong_Kind;
73 resolution.module_name = "main.aw";
74 resolution.symbol_name = "add";
75 resolution.filter = Compiler_Module_Name_Filter::Function;
76 resolution.binding.kind = Compiler_Module_Export_Kind::Global;
77
79 diagnostics, sm.span(file, 13, 16), resolution, "SDK002", "test callee");
80 ASSERT_EQ(diagnostics.size(), 1u);
81
82 std::ostringstream out;
83 diagnostics.render_plain(out);
84 EXPECT_NE(out.str().find("error[SDK002]: invalid test callee 'add'"), std::string::npos);
85 EXPECT_NE(out.str().find("resolves that name as Global"), std::string::npos);
86}
Reusable diagnostics for top-level inter-module name resolution.
size_t size_t int32_t * out
Definition ca-c-api.h:120
Diagnostic accumulator and renderer.
void render_plain(std::ostream &out) const
Renders all diagnostics as deterministic plain text.
size_t size() const noexcept
Returns the number of stored diagnostics.
Stores source files and resolves offsets into human-readable data.
Definition ah-source.H:184
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
Definition ah-source.H:258
#define TEST(name)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
size_t compiler_emit_module_name_resolution_diagnostic(Diagnostic_Engine &diagnostics, const Source_Span &span, const Compiler_Module_Name_Resolution &resolution, const std::string &code, const std::string &subject)
Emits one structured diagnostic for a module-name resolution failure.
Structured result returned by reusable module-name resolution.
Compiler_Module_Name_Resolution_Status status
long double resolution
ofstream file
Definition writeRb.C:51