Skip to content

Commit

Permalink
impl unit tests for template compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeCla committed Jan 15, 2024
1 parent ca181da commit 5b72cb0
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions ios/Nativebrik/NativebrikTests/placeholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,81 @@
//

import Foundation

import XCTest
@testable import Nativebrik

final class CompileTemplateTests: XCTestCase {
func testShouldCompileTemplate() throws {
let template = "Hello {{ value }}"
let result = compileTemplate(template: template) { key in
if key == "value" {
return "World"
} else {
return ""
}
}
XCTAssertEqual("Hello World", result)
}

func testShouldCompileTemplateWithMultiplePlaceholders() throws {
let template = "{{ value1 }} {{ value2 }}"
let result = compileTemplate(template: template) { key in
if key == "value1" {
return "Hello"
} else if key == "value2" {
return "World"
} else {
return ""
}
}
XCTAssertEqual("Hello World", result)
}

func testShouldCompileTemplateWithoutFmtButPipelined() throws {
let template = "Hello {{ value | }}"
let result = compileTemplate(template: template) { key in
return "World"
}
XCTAssertEqual("Hello World", result)
}

func testShouldCompileTemplateWithUnknownFmt() throws {
let template = "Hello {{ value | unknown }}"
let result = compileTemplate(template: template) { key in
if key == "value" {
return "World"
} else {
return ""
}
}
XCTAssertEqual("Hello World", result)
}

func testShouldCompileTemplateWithUpperFmt() throws {
let template = "HELLO {{ value | upper }}"
let result = compileTemplate(template: template) { key in
return "world"
}
XCTAssertEqual("HELLO WORLD", result)
}

func testShouldCompileTemplateWithLowerFmt() throws {
let template = "hello {{ value | lower }}"
let result = compileTemplate(template: template) { key in
return "WORLD"
}
XCTAssertEqual("hello world", result)
}

func testShouldCompileTemplateWithJsonFmt() throws {
let template = "{{ value | json }}"
let result = compileTemplate(template: template) { key in
let json: [String: Any] = [
"Key": "Value",
]
return json
}
XCTAssertEqual("{\"Key\":\"Value\"}", result)
}
}

0 comments on commit 5b72cb0

Please sign in to comment.