39 CHECK(SymbolManager::parseValue<uint16_t>(
"0xa1") == 0xa1);
40 CHECK(SymbolManager::parseValue<uint32_t>(
"0xa1") == 0xa1);
41 CHECK(SymbolManager::parseValue<uint16_t>(
"0x1234") == 0x1234);
42 CHECK(SymbolManager::parseValue<uint32_t>(
"0x1234") == 0x1234);
43 CHECK(SymbolManager::parseValue<uint16_t>(
"0XABCD") == 0xabcd);
44 CHECK(SymbolManager::parseValue<uint32_t>(
"0XABCD") == 0xabcd);
45 CHECK(SymbolManager::parseValue<uint16_t>(
"0x00002345") == 0x2345);
46 CHECK(SymbolManager::parseValue<uint32_t>(
"0x00002345") == 0x2345);
47 CHECK(SymbolManager::parseValue<uint16_t>(
"$fedc") == 0xfedc);
48 CHECK(SymbolManager::parseValue<uint32_t>(
"$fedc") == 0xfedc);
49 CHECK(SymbolManager::parseValue<uint16_t>(
"#11aA") == 0x11aa);
50 CHECK(SymbolManager::parseValue<uint32_t>(
"#11aA") == 0x11aa);
51 CHECK(SymbolManager::parseValue<uint16_t>(
"bbffh") == 0xbbff);
52 CHECK(SymbolManager::parseValue<uint32_t>(
"bbffh") == 0xbbff);
53 CHECK(SymbolManager::parseValue<uint16_t>(
"3210H") == 0x3210);
54 CHECK(SymbolManager::parseValue<uint32_t>(
"3210H") == 0x3210);
55 CHECK(SymbolManager::parseValue<uint16_t>(
"01234h") == 0x1234);
56 CHECK(SymbolManager::parseValue<uint32_t>(
"01234h") == 0x1234);
58 CHECK(SymbolManager::parseValue<uint16_t>(
"123") == 0x007b);
59 CHECK(SymbolManager::parseValue<uint32_t>(
"123") == 0x007b);
60 CHECK(SymbolManager::parseValue<uint16_t>(
"65535") == 0xffff);
61 CHECK(SymbolManager::parseValue<uint32_t>(
"65535") == 0xffff);
62 CHECK(SymbolManager::parseValue<uint16_t>(
"0020") == 0x0014);
63 CHECK(SymbolManager::parseValue<uint32_t>(
"0020") == 0x0014);
65 CHECK(SymbolManager::parseValue<uint16_t>(
"%1100") == 0x000c);
66 CHECK(SymbolManager::parseValue<uint32_t>(
"%1100") == 0x000c);
67 CHECK(SymbolManager::parseValue<uint16_t>(
"0b000100100011") == 0x0123);
68 CHECK(SymbolManager::parseValue<uint32_t>(
"0b000100100011") == 0x0123);
69 CHECK(SymbolManager::parseValue<uint16_t>(
"0B1111000001011000") == 0xf058);
70 CHECK(SymbolManager::parseValue<uint32_t>(
"0B1111000001011000") == 0xf058);
74 CHECK(SymbolManager::parseValue<uint16_t>(
"0xFEDX") == std::nullopt);
75 CHECK(SymbolManager::parseValue<uint32_t>(
"0xFEDGFF") == std::nullopt);
76 CHECK(SymbolManager::parseValue<uint16_t>(
"1234a") == std::nullopt);
77 CHECK(SymbolManager::parseValue<uint32_t>(
"1234567a") == std::nullopt);
78 CHECK(SymbolManager::parseValue<uint16_t>(
"-3") == std::nullopt);
79 CHECK(SymbolManager::parseValue<uint32_t>(
"-100000") == std::nullopt);
80 CHECK(SymbolManager::parseValue<uint16_t>(
"0b00112110") == std::nullopt);
81 CHECK(SymbolManager::parseValue<uint32_t>(
"0b00110113") == std::nullopt);
83 CHECK(SymbolManager::parseValue<uint16_t>(
"0x10000") == std::nullopt);
84 CHECK(SymbolManager::parseValue<uint16_t>(
"65536") == std::nullopt);
85 CHECK(SymbolManager::parseValue<uint16_t>(
"%11110000111100001") == std::nullopt);
86 CHECK(SymbolManager::parseValue<uint32_t>(
"0x100000000") == std::nullopt);
87 CHECK(SymbolManager::parseValue<uint32_t>(
"4294967296") == std::nullopt);
88 CHECK(SymbolManager::parseValue<uint32_t>(
"%111100001111000011110000111100001") == std::nullopt);
119 SECTION(
"on extension") {
120 std::string_view buffer =
"content doesn't matter";
128 SECTION(
".map extension") {
132 SECTION(
".sym extension") {
145 auto dummyParser = [](std::span<std::string_view> tokens) -> std::optional<Symbol> {
146 if (tokens.size() == 1)
return Symbol{std::string(tokens[0]), 123, {}, {}};
150 SECTION(
"empty file") {
151 std::string_view buffer;
153 CHECK(file.filename ==
"file.sym");
154 CHECK(file.type == SymbolFile::Type::GENERIC);
155 CHECK(file.symbols.empty());
157 SECTION(
"comment + symbol") {
158 std::string_view buffer =
159 "; This is a comment\n"
162 "bar ; comment on same line\n";
164 CHECK(file.filename ==
"file2.sym");
165 CHECK(file.type == SymbolFile::Type::NOICE);
166 REQUIRE(file.symbols.size() == 2);
167 CHECK(file.symbols[0].name ==
"bla");
168 CHECK(file.symbols[0].value == 123);
169 CHECK(file.symbols[1].name ==
"bar");
170 CHECK(file.symbols[1].value == 123);
197 std::string_view buffer =
199 "def bar 234h ; comment\n"
201 "def error 99 extra stuff\n";
203 CHECK(file.filename ==
"noice.sym");
204 CHECK(file.type == SymbolFile::Type::NOICE);
205 REQUIRE(file.symbols.size() == 2);
206 CHECK(file.symbols[0].name ==
"foo");
207 CHECK(file.symbols[0].value == 1);
208 CHECK(file.symbols[0].segment == std::nullopt);
209 CHECK(file.symbols[1].name ==
"bar");
210 CHECK(file.symbols[1].value == 0x234);
211 CHECK(file.symbols[1].segment == std::nullopt);
216 std::string_view buffer =
218 "def bar 234h ; comment\n"
220 "def error 99 extra stuff\n"
221 "def baz 123456h ; comment\n";
223 CHECK(file.filename ==
"noice.sym");
224 CHECK(file.type == SymbolFile::Type::NOICE);
225 REQUIRE(file.symbols.size() == 3);
226 CHECK(file.symbols[0].name ==
"foo");
227 CHECK(file.symbols[0].value == 1);
228 CHECK(file.symbols[0].segment == 0);
229 CHECK(file.symbols[1].name ==
"bar");
230 CHECK(file.symbols[1].value == 0x234);
231 CHECK(file.symbols[1].segment == 0);
232 CHECK(file.symbols[2].name ==
"baz");
233 CHECK(file.symbols[2].value == 0x3456);
234 CHECK(file.symbols[2].segment == 0x12);
286 std::string_view buffer =
287 "; this file was created with wlalink\n"
288 "; no$gmb symbolic information for \"test.rom\".\n"
290 "00:402d main@main_loop\n"
291 "00:404f Game_Initialize\n"
292 "00:404e Game_Update\n";
294 CHECK(file.filename ==
"myfile.sym");
295 CHECK(file.type == SymbolFile::Type::WLALINK_NOGMB);
296 REQUIRE(file.symbols.size() == 4);
297 CHECK(file.symbols[0].name ==
"main");
298 CHECK(file.symbols[0].value == 0x4010);
299 CHECK(file.symbols[1].name ==
"main@main_loop");
300 CHECK(file.symbols[1].value == 0x402d);
301 CHECK(file.symbols[2].name ==
"Game_Initialize");
302 CHECK(file.symbols[2].value == 0x404f);
303 CHECK(file.symbols[3].name ==
"Game_Update");
304 CHECK(file.symbols[3].value == 0x404e);
309 std::string_view buffer =
310 "ignore1 text 2CE7 ignore2 0AEE\n"
311 "ignore3 2E58 ignore3 text 2E4C\n"
313 "asllmod text 2CE7 asllsub 0AEE\n"
314 "cret 2E58 csv text 2E4C\n"
318 CHECK(file.filename ==
"link.map");
319 CHECK(file.type == SymbolFile::Type::LINKMAP);
320 REQUIRE(file.symbols.size() == 6);
321 CHECK(file.symbols[0].name ==
"asllmod");
322 CHECK(file.symbols[0].value == 0x2ce7);
323 CHECK(file.symbols[1].name ==
"asllsub");
324 CHECK(file.symbols[1].value == 0x0aee);
325 CHECK(file.symbols[2].name ==
"cret");
326 CHECK(file.symbols[2].value == 0x2e58);
327 CHECK(file.symbols[3].name ==
"csv");
328 CHECK(file.symbols[3].value == 0x2e4c);
329 CHECK(file.symbols[4].name ==
"single");
330 CHECK(file.symbols[4].value == 0x9876);
331 CHECK(file.symbols[5].name ==
"last");
332 CHECK(file.symbols[5].value == 0x8765);