diff --git a/ios/Nativebrik/NativebrikTests/placeholder.swift b/ios/Nativebrik/NativebrikTests/placeholder.swift index 4aa4ceb..dddbc3c 100644 --- a/ios/Nativebrik/NativebrikTests/placeholder.swift +++ b/ios/Nativebrik/NativebrikTests/placeholder.swift @@ -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) + } +}