diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66cfdab..696e60b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,3 +22,5 @@ jobs: - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - run: cargo build --verbose - run: cargo test --verbose + - run: cargo build --all-features --verbose + - run: cargo test --all-features --verbose diff --git a/src/lib.rs b/src/lib.rs index 726e88f..6f703bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,7 @@ //! ``` //! //! ```rust +//! # #[cfg(feature = "trie")] { //! use general_sam::{sam::GeneralSAM, trie::Trie}; //! //! let mut trie = Trie::default(); @@ -82,6 +83,7 @@ //! //! assert!(!sam.get_root_state().feed_chars("bye").is_accepting()); //! assert!(sam.get_root_state().feed_chars("bye").is_nil()); +//! # } //! ``` //! //! # References diff --git a/src/tests.rs b/src/tests.rs index 8aa703d..d3d0829 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,10 +1,4 @@ -use rand::{ - distributions::{Alphanumeric, DistString}, - rngs::StdRng, - Rng, SeedableRng, -}; - -use crate::{sam::GeneralSAM, trie::Trie, SAM_ROOT_NODE_ID}; +use crate::sam::GeneralSAM; #[test] fn test_example_from_chars() { @@ -40,8 +34,11 @@ fn test_example_from_bytes() { assert!(!state.is_accepting() && state.is_nil() && !state.is_root()); } +#[cfg(feature = "trie")] #[test] fn test_example_from_trie() { + use crate::trie::Trie; + let mut trie = Trie::default(); trie.insert_iter("hello".chars()); @@ -120,7 +117,10 @@ fn test_chinese_chars() { println!("state \"你好\": {:?}", state.node_id); } +#[cfg(feature = "trie")] fn test_trie_suffix(vocab: &[&str]) { + use crate::trie::Trie; + let mut trie = Trie::default(); vocab.iter().for_each(|word| { trie.insert_iter(word.chars()); @@ -160,20 +160,32 @@ fn test_trie_suffix(vocab: &[&str]) { }); } +#[cfg(feature = "trie")] #[test] fn test_chiense_trie_suffix() { let vocab = ["歌曲", "聆听歌曲", "播放歌曲", "歌词", "查看歌词"]; test_trie_suffix(&vocab); } +#[cfg(feature = "trie")] #[test] fn test_simple_trie_suffix() { let vocab = ["ac", "bb", "b", "cc", "aabb", "a", "ba", "c", "aa"]; test_trie_suffix(&vocab); } +#[cfg(feature = "trie")] #[test] fn test_topo_and_suf_len_sorted_order() { + use rand::{ + distributions::{Alphanumeric, DistString}, + rngs::StdRng, + Rng, SeedableRng, + }; + + use crate::trie::Trie; + use crate::SAM_ROOT_NODE_ID; + let mut rng = StdRng::seed_from_u64(1134759173975); for _ in 0..10000 { let mut trie = Trie::default();