diff --git a/this_algorithm/tests/display.rs b/this_algorithm/tests/display.rs index fd5d923..5cae6e9 100644 --- a/this_algorithm/tests/display.rs +++ b/this_algorithm/tests/display.rs @@ -1,4 +1,22 @@ +use std::str::FromStr; +use this_algorithm::Address; mod common; +#[test] +fn test_v0() { + t("grape orange apple 1000"); + t("1000 apple orange grape"); + t("\t\tgrape\n\t orange apple 1000 \t "); + t("\n1000 APPlE oRAnGE GrAPe\n"); + + ll(37.55512, -76.89212); + assert!(false); +} +fn ll(lat: f64, lon: f64) { + eprintln!("{lat}, {lon} =>\t{}", Address::from_lat_lon(lat, lon)); +} +fn t(s: &str) { + eprintln!("{:?}", Address::from_str(s)); +} // #[test] // fn test_address() { diff --git a/words/build.rs b/words/build.rs index f4aaa79..ff39e23 100644 --- a/words/build.rs +++ b/words/build.rs @@ -35,10 +35,12 @@ fn main() { } fn write_words(mut file: impl Write, words: &[Word]) { + let len = words.len(); + writeln!( &mut file, r#"/// Static array of `Word` -pub const WORDS: &[Word] = &["# +pub static WORDS: [Word; {len}] = ["# ) .unwrap(); @@ -57,8 +59,7 @@ fn write_word_map(mut file: impl Write, words: &[Word]) { writeln!( &mut file, r#"/// Mapping from all caps `&str` to `&'static Word` - pub static WORD_MAP: phf::Map<&'static str, &'static Word> = - {};"#, + pub static WORD_MAP: phf::Map<&'static str, &'static Word> = {};"#, word_map.build() ) .unwrap(); @@ -73,8 +74,8 @@ fn write_number_to_words(mut file: impl Write, words: &[Word]) { writeln!( &mut file, - // "pub const NUMBER_TO_WORDS: &[&[usize]] = &[" - "pub const NUMBER_TO_WORDS: &[&[&'static Word]] = &[" + // "pub static NUMBER_TO_WORDS: &[&[usize]] = &[" + "pub static NUMBER_TO_WORDS: &[&[&'static Word]] = &[" ) .unwrap(); diff --git a/words/src/lib.rs b/words/src/lib.rs index c620849..99c34be 100644 --- a/words/src/lib.rs +++ b/words/src/lib.rs @@ -16,7 +16,7 @@ pub struct Word<'a> { impl Display for Word<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self) + write!(f, "{}", self.word) } }