Skip to content

Commit

Permalink
Merge 3395f47 into 4eb7191
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed May 2, 2023
2 parents 4eb7191 + 3395f47 commit c8d4796
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
36 changes: 16 additions & 20 deletions clafrica-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
//!
//! Example
//! ```
//! use clafrica_lib::{bst, utils};
//! use clafrica_lib::{text_buffer, utils};
//!
//! // Build a BST
//! let root = bst::Node::default();
//! // Build a TextBuffer
//! let root = text_buffer::Node::default();
//! root.insert(vec!['a', 'f'], "ɑ".to_owned());
//! root.insert(vec!['a', 'f', '1'], "ɑ̀".to_owned());
//!
//! // Bulk insert of data in the BST
//! // Bulk insert of data in the TextBuffer
//! let data = vec![["af11", "ɑ̀ɑ̀"], ["?.", "ʔ"]];
//! utils::build_map(data);
//!
Expand All @@ -30,14 +30,14 @@
//! assert_eq!(node.unwrap().take(), Some("ɑ".to_owned()));
//!
//! // Test our cursor
//! let mut cursor = bst::Cursor::new(root, 10);
//! let mut cursor = text_buffer::Cursor::new(root, 10);
//! let code = "af1";
//! code.chars().for_each(|c| {cursor.hit(c);});
//! assert_eq!(cursor.state(), (Some("ɑ̀".to_owned()), 3));
//! assert_eq!(cursor.undo(), Some("ɑ̀".to_owned()));
//! ```

pub mod bst {
pub mod text_buffer {
use std::collections::{HashMap, VecDeque};
use std::{cell::RefCell, rc::Rc};

Expand All @@ -64,7 +64,7 @@ pub mod bst {
}
}

/// Insert a path in the BST.
/// Insert a path in the TextBuffer.
pub fn insert(&self, path: Vec<char>, value: String) {
if let Some(character) = path.clone().first() {
let new_node = Rc::new(Self::new(self.depth + 1));
Expand Down Expand Up @@ -164,7 +164,7 @@ pub mod bst {
}

pub mod utils {
use crate::bst;
use crate::text_buffer;
use std::{fs, io};

/// Load the clafrica code from a plain text file.
Expand All @@ -182,9 +182,9 @@ pub mod utils {
Ok(data)
}

/// Build a BST from the clafrica code.
pub fn build_map(data: Vec<[&str; 2]>) -> bst::Node {
let root = bst::Node::default();
/// Build a TextBuffer from the clafrica code.
pub fn build_map(data: Vec<[&str; 2]>) -> text_buffer::Node {
let root = text_buffer::Node::default();

data.iter().for_each(|e| {
root.insert(e[0].chars().collect(), e[1].to_owned());
Expand Down Expand Up @@ -223,9 +223,9 @@ mod tests {

#[test]
fn test_node() {
use crate::bst;
use crate::text_buffer;

let root = bst::Node::default();
let root = text_buffer::Node::default();

assert!(root.is_root());

Expand All @@ -245,7 +245,7 @@ mod tests {

#[test]
fn test_cursor() {
use crate::bst;
use crate::text_buffer;
use crate::utils;

macro_rules! hit {
Expand All @@ -269,7 +269,7 @@ mod tests {
.collect(),
);

let mut cursor = bst::Cursor::new(root, 10);
let mut cursor = text_buffer::Cursor::new(root, 10);

assert_eq!(cursor.state(), (None, 0));

Expand Down Expand Up @@ -308,11 +308,7 @@ mod tests {
'2', 'a', '2', 'a', '_'
);
assert_eq!(
cursor
.to_path()
.into_iter()
.filter_map(|e| e)
.collect::<Vec<_>>(),
cursor.to_path().into_iter().flatten().collect::<Vec<_>>(),
vec!["íá", "á̠"]
);

Expand Down
4 changes: 2 additions & 2 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clafrica_lib::bst;
use clafrica_lib::text_buffer;

struct Cursor<'a> {
stack: Vec<&'a str>,
node: &'a bst::Node,
node: &'a text_buffer::Node,
}

fn run() {
Expand Down

0 comments on commit c8d4796

Please sign in to comment.