// SPDX-FileCopyrightText: Amolith // // SPDX-License-Identifier: AGPL-3.0-or-later import gleam/string import gleeunit/should import prompts // --- system tests --- pub fn system_returns_prompt_test() { let result = prompts.system() should.be_true(result |> contains("text transformation tool")) should.be_true(result |> contains("")) } // --- build_user_message tests --- pub fn build_user_message_with_directions_test() { let result = prompts.build_user_message("hello", "make it loud") should.be_true(result |> contains("\nhello\n")) should.be_true( result |> contains("\nmake it loud\n"), ) should.be_true(result |> contains("Transform the text in ")) } pub fn build_user_message_without_directions_test() { let result = prompts.build_user_message("hello", "") should.be_true(result |> contains("\nhello\n")) should.be_false(result |> contains("")) should.be_true(result |> contains("Transform the text in ")) } pub fn build_user_message_trims_directions_test() { let result = prompts.build_user_message("hello", " ") should.be_false(result |> contains("")) } // --- extract_code_block tests --- pub fn extract_simple_code_block_test() { let input = "```\nhello world\n```" prompts.extract_code_block(input) |> should.equal("hello world") } pub fn extract_code_block_with_language_test() { let input = "```json\n{\"key\": \"value\"}\n```" prompts.extract_code_block(input) |> should.equal("{\"key\": \"value\"}") } pub fn extract_code_block_with_surrounding_text_test() { let input = "Here's the result:\n```\ntransformed\n```\nHope that helps!" prompts.extract_code_block(input) |> should.equal("transformed") } pub fn extract_returns_full_text_when_no_code_block_test() { let input = "Just plain text without any code blocks." prompts.extract_code_block(input) |> should.equal(input) } pub fn extract_uses_first_code_block_test() { let input = "```\nfirst\n```\n\n```\nsecond\n```" prompts.extract_code_block(input) |> should.equal("first") } pub fn extract_handles_empty_code_block_test() { let input = "```\n```" prompts.extract_code_block(input) |> should.equal("") } pub fn extract_handles_unclosed_code_block_test() { let input = "```\nunclosed content here" prompts.extract_code_block(input) |> should.equal(input) } fn contains(haystack: String, needle: String) -> Bool { string.contains(haystack, needle) }