diff --git a/Cargo.lock b/Cargo.lock index b468ae7..2aa11ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,7 @@ version = "0.3.0" dependencies = [ "clap", "colored", + "cuentitos-common", "glob", ] diff --git a/common/src/lib.rs b/common/src/lib.rs index 6499353..832fc7c 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,8 @@ +pub mod test_case; + pub type StringId = usize; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum Block { String(StringId) } diff --git a/compat/src/test_case.rs b/common/src/test_case.rs similarity index 100% rename from compat/src/test_case.rs rename to common/src/test_case.rs diff --git a/compat/Cargo.toml b/compat/Cargo.toml index 1964010..7439bd3 100644 --- a/compat/Cargo.toml +++ b/compat/Cargo.toml @@ -10,3 +10,4 @@ default-run = 'cuentitos-compat' clap = { version = "4.5.23", features = ["derive"] } colored = "3.0.0" glob = "0.3.1" +cuentitos-common = { path = "../common" } diff --git a/compat/src/main.rs b/compat/src/main.rs index cf02ab5..72fcdbb 100644 --- a/compat/src/main.rs +++ b/compat/src/main.rs @@ -1,13 +1,12 @@ use crate::test_runner::TestResult; use crate::test_runner::TestRunner; -use crate::test_case::TestCase; use glob::{glob, GlobError}; use std::path::PathBuf; use clap::Parser; use colored::Colorize; +use cuentitos_common::test_case::TestCase; mod test_runner; -mod test_case; #[derive(Parser, Debug)] struct Args { diff --git a/docs/architecture/000005-lines-of-text.md b/docs/architecture/000005-lines-of-text.md new file mode 100644 index 0000000..c5d72e7 --- /dev/null +++ b/docs/architecture/000005-lines-of-text.md @@ -0,0 +1,30 @@ +# Lines of Text + +### Submitters + +- Fran Tufro + +## Change Log + +- 2025-01-21 - [First Draft of ADR created](https://github.com/hiddenpeopleclub/cuentitos/pull/52). + +## Context + +Cuentitos language wants to be as writer friendly as possible, because of that +is going to be text-first. + +We want to support a scripting format that will let a writer do as much as they +can with text, minimizing the use of mouse or additional tools. + +The first step is to support writing lines of text that get parsed and +transformed into objects that can be processed by the runtime. + +## Proposed Design + +I will split functionality from data when it comes to string management. + +The parser will iterate through all the script and provide an id to each line +of text, this id will be used to reference the line of text in the string table. + +This is to better support internationalization, as the string table will be +replaced by the correct language at runtime. diff --git a/parser/src/line_parser/mod.rs b/parser/src/line_parser/mod.rs index 5a49818..93f27dd 100644 --- a/parser/src/line_parser/mod.rs +++ b/parser/src/line_parser/mod.rs @@ -21,3 +21,19 @@ pub fn parse(line: Line) -> Result { } ) } + +mod tests { + use super::*; + +#[test] + fn test_parse() { + let line = Line { + parsed: false, + text: "Hello, world!", + }; + + let result = super::parse(line).unwrap(); + assert_eq!(result.block, super::Block::String(1)); + assert_eq!(result.string, "Hello, world!"); + } +} diff --git a/parser/src/parser.rs b/parser/src/parser.rs index f43ef7f..efcb10b 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -11,8 +11,6 @@ pub enum ParseError { UnexpectedEndOfFile, } - - impl Parser { pub fn parse(&mut self, script: A) -> Result where A: AsRef @@ -38,3 +36,25 @@ impl Parser { Ok(database) } } + + +mod test { + use cuentitos_common::test_case::TestCase; + use super::*; + + #[test] + fn test_single_line_script() { + let test_case = TestCase::from_string( + include_str!("../../compatibility-tests/00000000001-single-line-and-end.md"), + "single-line.md" + ); + + let mut parser = Parser::default(); + let database = parser.parse(test_case.script).unwrap(); + assert_eq!(database.blocks.len(), 1); + assert_eq!(database.strings.len(), 1); + assert_eq!(database.blocks[0], Block::String(0)); + assert_eq!(database.strings[0], "This is a single line"); + + } +}