|
| 1 | +// |
| 2 | +// LexerSliceReleaseTests.swift |
| 3 | +// |
| 4 | +// |
| 5 | +// Created by Wes Wickwire on 6/27/26. |
| 6 | +// |
| 7 | + |
| 8 | +import Testing |
| 9 | +@testable import Compiler |
| 10 | + |
| 11 | +/// These tests only failed in a release build. |
| 12 | +@Suite |
| 13 | +struct LexerSliceReleaseTests { |
| 14 | + @Test func escapedIdentifierStripsDelimiters() { |
| 15 | + #expect(firstIdentifier("\"MyModel.ID\"") == "MyModel.ID") |
| 16 | + #expect(firstIdentifier("[MyModel.ID]") == "MyModel.ID") |
| 17 | + #expect(firstIdentifier("`MyModel.ID`") == "MyModel.ID") |
| 18 | + } |
| 19 | + |
| 20 | + @Test func stringLiteralStripsQuotes() { |
| 21 | + #expect(firstString("'hello world'") == "hello world") |
| 22 | + } |
| 23 | + |
| 24 | + @Test func hexLiteral() { |
| 25 | + #expect(firstHex("0xFF") == 255) |
| 26 | + } |
| 27 | + |
| 28 | + @Test func scientificNotation() { |
| 29 | + #expect(firstDouble("1e3") == 1000) |
| 30 | + #expect(firstDouble("1e-2") == 0.01) |
| 31 | + } |
| 32 | + |
| 33 | + @Test func aliasedColumnTypeGeneratesUnquotedName() { |
| 34 | + var compiler = Compiler() |
| 35 | + let (_, diags) = compiler.compile(migration: """ |
| 36 | + CREATE TABLE myTable ( |
| 37 | + id INTEGER AS "MyModel.ID" |
| 38 | + ); |
| 39 | + """) |
| 40 | + #expect(diags.isEmpty) |
| 41 | + let table = compiler.schema.tables.values.first! |
| 42 | + let col = table.columns.values.first! |
| 43 | + #expect(!String(describing: col.type).contains("\"")) |
| 44 | + } |
| 45 | + |
| 46 | + private func firstIdentifier(_ src: String) -> String? { |
| 47 | + var lexer = Lexer(source: src) |
| 48 | + while true { |
| 49 | + let t = lexer.next() |
| 50 | + if case .eof = t.kind { return nil } |
| 51 | + if case let .identifier(v) = t.kind { return String(v) } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private func firstString(_ src: String) -> String? { |
| 56 | + var lexer = Lexer(source: src) |
| 57 | + while true { |
| 58 | + let t = lexer.next() |
| 59 | + if case .eof = t.kind { return nil } |
| 60 | + if case let .string(v) = t.kind { return String(v) } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private func firstHex(_ src: String) -> Int? { |
| 65 | + var lexer = Lexer(source: src) |
| 66 | + while true { |
| 67 | + let t = lexer.next() |
| 68 | + if case .eof = t.kind { return nil } |
| 69 | + if case let .hex(v) = t.kind { return v } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + private func firstDouble(_ src: String) -> Double? { |
| 74 | + var lexer = Lexer(source: src) |
| 75 | + while true { |
| 76 | + let t = lexer.next() |
| 77 | + if case .eof = t.kind { return nil } |
| 78 | + if case let .double(v) = t.kind { return v } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments