four-word-networking 2.7.0

Convert IP addresses to memorable, family-friendly word groups. Interactive TUI with real-time autocomplete. IPv4 = 4 words, IPv6 = 6-12 words. Perfect reconstruction with progressive hints.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
//! 4wn - Four-Word Networking CLI
//!
//! Command-line tool with interactive autocomplete mode by default.
//!
//! Default (no args): Interactive mode with autocomplete hints and progressive completion
//! With arguments: Direct conversion between IP addresses and words
//!
//! Features:
//! - Interactive mode with hints at 3+ characters, auto-complete at 5 characters
//! - Perfect reconstruction for IPv4 (4 words) and adaptive compression for IPv6 (6/9/12 words)
//! - Real-time validation and completion suggestions
//!
//! Usage:
//!   4wn                         # Interactive mode (default)
//!   4wn 192.168.1.1:80          # Direct encode to 4 words
//!   4wn a abaddon amphipoda arian  # Direct decode to IP:port
//!   4wn [2001:db8::1]:443      # Direct encode IPv6 to words

use clap::Parser;
use four_word_networking::{FourWordAdaptiveEncoder, FourWordError, Result};
use std::io::{self, Write};
use std::process;

// TUI imports for real-time interactive mode
use crossterm::{
    cursor,
    event::{self, Event, KeyCode, KeyEventKind},
    execute, queue,
    style::{Color, Print, ResetColor, SetForegroundColor},
    terminal::{self, ClearType},
};

#[derive(Parser)]
#[command(
    name = "4wn",
    about = "Four-Word Networking - Interactive IP address to words converter",
    long_about = "Interactive CLI for converting between IP addresses and memorable words.\n\
                  Default: Interactive mode with autocomplete hints and progressive completion.\n\
                  With arguments: Direct conversion between IP addresses and four-word combinations.\n\
                  Features perfect reconstruction for IPv4 (4 words) and adaptive compression for IPv6 (6/9/12 words).",
    version
)]
struct Cli {
    /// Input to convert (IP:port or words) - if provided, performs direct conversion
    /// If no input provided, starts interactive mode with autocomplete
    input: Vec<String>,

    /// Show detailed information
    #[arg(short, long)]
    verbose: bool,

    /// Output format for scripting (minimal output)
    #[arg(short, long)]
    quiet: bool,

    /// Show completion hints for a prefix (utility mode)
    #[arg(short, long)]
    complete: Option<String>,

    /// Validate partial word input and show suggestions (utility mode)
    #[arg(long)]
    validate: Option<String>,
}

fn main() {
    let cli = Cli::parse();

    if let Err(e) = run(cli) {
        eprintln!("Error: {e}");
        process::exit(1);
    }
}

fn run(cli: Cli) -> Result<()> {
    let encoder = FourWordAdaptiveEncoder::new()?;

    // Handle utility modes first
    if let Some(prefix) = cli.complete {
        show_completion_hints(&encoder, &prefix)?;
        return Ok(());
    }

    if let Some(partial) = cli.validate {
        show_validation_results(&encoder, &partial)?;
        return Ok(());
    }

    // If no input provided, start interactive mode
    if cli.input.is_empty() {
        return interactive_mode(&encoder, cli.verbose);
    }

    // Direct conversion mode with arguments
    let input = if cli.input.len() == 1 {
        // Single argument - could be IP or words with separators
        cli.input[0].trim().to_string()
    } else {
        // Multiple arguments - treat as space-separated words
        cli.input.join(" ")
    };

    // Detect input type based on content
    if looks_like_words(&input) {
        // Input is words, decode to IP:port
        decode_words(&encoder, &input, cli.verbose, cli.quiet)
    } else {
        // Input is IP:port, encode to words
        encode_address(&encoder, &input, cli.verbose, cli.quiet)
    }
}

/// Check if input looks like words (contains dots, dashes, spaces, all alphabetic)
fn looks_like_words(input: &str) -> bool {
    // Handle space-separated words or separator-based words
    let segments: Vec<&str> = if input.contains(' ') && !input.contains('-') && !input.contains(':')
    {
        // Space-separated words (not IPv6 with colons)
        input.split_whitespace().collect()
    } else if input.contains('.')
        || input.contains('-')
        || input.contains('_')
        || input.contains('+')
    {
        // Split by any separator
        input.split(|c: char| ".-_+".contains(c)).collect()
    } else {
        // No separators - not words
        return false;
    };

    // Must be 4 (IPv4), 6, 9, or 12 (IPv6) segments
    if segments.len() != 4 && segments.len() != 6 && segments.len() != 9 && segments.len() != 12 {
        return false;
    }

    // Check if all segments are alphabetic and meet minimum length requirement
    segments
        .iter()
        .all(|segment| !segment.is_empty() && segment.chars().all(|c| c.is_alphabetic()))
}

/// Encode IP address to words
fn encode_address(
    encoder: &FourWordAdaptiveEncoder,
    address: &str,
    verbose: bool,
    quiet: bool,
) -> Result<()> {
    let words = encoder.encode(address)?;

    if quiet {
        // Minimal output for scripting
        println!("{words}");
    } else if verbose {
        // Detailed output
        println!("Input: {address}");
        println!("Words: {words}");
        println!("Encoding: Perfect (100% reversible)");

        if words.contains('.') && !words.contains('-') {
            println!("Type: IPv4 (dot separators, lowercase)");
        } else if words.contains('-') {
            println!("Type: IPv6 (dash separators, title case)");
        }

        println!("Features:");
        println!("  • Perfect IPv4 reconstruction (4 words)");
        println!("  • Adaptive IPv6 compression (6, 9, or 12 words)");
        println!("  • Guaranteed perfect reconstruction");
    } else {
        // Normal output
        println!("{words}");
    }

    Ok(())
}

/// Decode words to IP address
fn decode_words(
    encoder: &FourWordAdaptiveEncoder,
    words: &str,
    verbose: bool,
    quiet: bool,
) -> Result<()> {
    let address = encoder.decode(words)?;

    if quiet {
        // Minimal output for scripting
        println!("{address}");
    } else if verbose {
        // Detailed output
        println!("Input: {words}");
        println!("Address: {address}");
        println!("Decoding: Perfect reconstruction");

        if words.contains('.') && !words.contains('-') {
            println!("Type: IPv4 (detected from dot separators)");
        } else if words.contains('-') {
            println!("Type: IPv6 (detected from dash separators)");
        }
    } else {
        // Normal output
        println!("{address}");
    }

    Ok(())
}

/// Interactive mode with autocomplete and hints
/// Interactive mode with real-time character input and autocomplete
fn interactive_mode(encoder: &FourWordAdaptiveEncoder, verbose: bool) -> Result<()> {
    // Enable raw mode for character-by-character input
    terminal::enable_raw_mode()
        .map_err(|e| FourWordError::InvalidInput(format!("Failed to enable raw mode: {e}")))?;

    // Clean up terminal on exit
    let cleanup = || {
        let _ = terminal::disable_raw_mode();
        let _ = execute!(io::stdout(), cursor::Show, ResetColor);
    };

    // Set up panic hook to cleanup terminal
    let original_hook = std::panic::take_hook();
    std::panic::set_hook(Box::new(move |info| {
        let _ = terminal::disable_raw_mode();
        let _ = execute!(io::stdout(), cursor::Show, ResetColor);
        original_hook(info);
    }));

    let result = run_interactive_tui(encoder, verbose);

    // Always cleanup
    cleanup();

    result
}

/// Run the actual TUI interactive mode
fn run_interactive_tui(encoder: &FourWordAdaptiveEncoder, verbose: bool) -> Result<()> {
    let mut stdout = io::stdout();

    // Clear screen and show header
    execute!(
        stdout,
        terminal::Clear(ClearType::All),
        cursor::MoveTo(0, 0),
        Print(
            "🌐 Four-Word Networking - Interactive Mode
"
        ),
        Print(
            "Real-time autocomplete: Progressive hints at 3+ chars, auto-complete at 5 chars
"
        ),
        Print(
            "Commands: quit/exit to leave, Ctrl+C to interrupt, Tab for completion

"
        )
    )
    .map_err(|e| FourWordError::InvalidInput(format!("Terminal error: {e}")))?;

    let mut current_input = String::new();
    let mut cursor_pos = 0;
    let mut completed_words = Vec::<String>::new();

    loop {
        // Render current state
        render_ui(
            &mut stdout,
            &current_input,
            cursor_pos,
            &completed_words,
            encoder,
            verbose,
        )?;

        // Read next event
        if let Ok(event) = event::read() {
            match event {
                Event::Key(key_event) if key_event.kind == KeyEventKind::Press => {
                    match key_event.code {
                        KeyCode::Char('c')
                            if key_event.modifiers.contains(event::KeyModifiers::CONTROL) =>
                        {
                            break;
                        }
                        KeyCode::Char('q')
                            if key_event.modifiers.contains(event::KeyModifiers::CONTROL) =>
                        {
                            break;
                        }
                        KeyCode::Enter => {
                            if handle_enter(&current_input, &mut completed_words, encoder, verbose)?
                            {
                                break;
                            }
                            current_input.clear();
                            cursor_pos = 0;
                        }
                        KeyCode::Tab => {
                            // Handle tab completion
                            if let Some(completion) = get_best_completion(encoder, &current_input) {
                                current_input = completion;
                                cursor_pos = current_input.len();
                            }
                        }
                        KeyCode::Backspace => {
                            if cursor_pos > 0 {
                                current_input.remove(cursor_pos - 1);
                                cursor_pos -= 1;
                            }
                        }
                        KeyCode::Delete => {
                            if cursor_pos < current_input.len() {
                                current_input.remove(cursor_pos);
                            }
                        }
                        KeyCode::Left => {
                            cursor_pos = cursor_pos.saturating_sub(1);
                        }
                        KeyCode::Right => {
                            if cursor_pos < current_input.len() {
                                cursor_pos += 1;
                            }
                        }
                        KeyCode::Home => {
                            cursor_pos = 0;
                        }
                        KeyCode::End => {
                            cursor_pos = current_input.len();
                        }
                        KeyCode::Char(c) => {
                            // Insert character at cursor position
                            current_input.insert(cursor_pos, c);
                            cursor_pos += 1;

                            // Auto-complete at 5 characters if unique
                            if current_input.len() >= 5
                                && let Some(word) = encoder.auto_complete_at_five(&current_input)
                            {
                                current_input = word;
                                cursor_pos = current_input.len();
                            }
                        }
                        _ => {}
                    }
                }
                _ => {}
            }
        }
    }

    // Clear screen and show goodbye
    execute!(
        stdout,
        terminal::Clear(ClearType::All),
        cursor::MoveTo(0, 0),
        Print(
            "Goodbye! 👋
"
        )
    )
    .map_err(|e| FourWordError::InvalidInput(format!("Terminal error: {e}")))?;

    Ok(())
}

/// Render the TUI interface
fn render_ui(
    stdout: &mut io::Stdout,
    current_input: &str,
    cursor_pos: usize,
    completed_words: &[String],
    encoder: &FourWordAdaptiveEncoder,
    _verbose: bool,
) -> Result<()> {
    // Move to start of input area (line 5)
    queue!(stdout, cursor::MoveTo(0, 4))?;

    // Clear from cursor to end of screen
    queue!(stdout, terminal::Clear(ClearType::FromCursorDown))?;

    // Show completed words
    if !completed_words.is_empty() {
        queue!(
            stdout,
            SetForegroundColor(Color::Green),
            Print("Words: "),
            ResetColor,
            Print(&completed_words.join(" ")),
            Print(&format!(" ({}/4)", completed_words.len())),
            Print(
                "

"
            )
        )?;
    }

    // Show current input prompt
    queue!(stdout, Print("4wn> "), Print(current_input))?;

    // Show hints if input is 3+ characters
    if current_input.len() >= 3 {
        let hints = encoder.get_word_hints(current_input);
        if !hints.is_empty() {
            queue!(
                stdout,
                Print(
                    "

"
                )
            )?;

            if hints.len() == 1 {
                queue!(
                    stdout,
                    SetForegroundColor(Color::Green),
                    Print("✓ Complete match: "),
                    ResetColor,
                    Print(&hints[0])
                )?;
            } else {
                queue!(
                    stdout,
                    SetForegroundColor(Color::Yellow),
                    Print(&format!("💡 {} matches: ", hints.len())),
                    ResetColor
                )?;

                // Show up to 5 hints
                for (i, hint) in hints.iter().take(5).enumerate() {
                    if i > 0 {
                        queue!(stdout, Print(", "))?;
                    }
                    queue!(stdout, Print(hint))?;
                }
                if hints.len() > 5 {
                    queue!(stdout, Print(&format!(" (+{} more)", hints.len() - 5)))?;
                }
            }

            // Show auto-complete message at 5+ chars
            if current_input.len() >= 5 && hints.len() == 1 {
                queue!(
                    stdout,
                    Print(
                        "
"
                    ),
                    SetForegroundColor(Color::Cyan),
                    Print("   Press any key to auto-complete"),
                    ResetColor
                )?;
            }
        } else {
            queue!(
                stdout,
                Print(
                    "

"
                ),
                SetForegroundColor(Color::Red),
                Print("❌ No matches found"),
                ResetColor
            )?;
        }
    }

    // Position cursor at input location
    let cursor_col = 5 + cursor_pos; // "4wn> " = 5 chars
    queue!(
        stdout,
        cursor::MoveTo(
            cursor_col as u16,
            4 + if completed_words.is_empty() { 0 } else { 2 }
        )
    )?;

    stdout
        .flush()
        .map_err(|e| FourWordError::InvalidInput(format!("Flush error: {e}")))?;
    Ok(())
}

/// Handle Enter key press
fn handle_enter(
    input: &str,
    completed_words: &mut Vec<String>,
    encoder: &FourWordAdaptiveEncoder,
    _verbose: bool,
) -> Result<bool> {
    let input = input.trim();

    // Handle special commands
    match input.to_lowercase().as_str() {
        "quit" | "exit" => return Ok(true),
        "clear" => {
            completed_words.clear();
            return Ok(false);
        }
        "" => return Ok(false),
        _ => {}
    }

    // Try to process as complete address
    if (input.contains(':') || input.contains('[') || input.parse::<std::net::IpAddr>().is_ok())
        && let Ok(encoded) = encoder.encode(input)
    {
        println!("\n🌐 {input}{encoded}\n");
        return Ok(false);
    }

    // Try to process as complete word sequence
    if looks_like_words(input)
        && let Ok(decoded) = encoder.decode(input)
    {
        println!("\n🌐 {input}{decoded}\n");
        return Ok(false);
    }

    // Add as word to completion
    if encoder.is_valid_prefix(input) {
        let hints = encoder.get_word_hints(input);
        if hints.len() == 1 {
            completed_words.push(hints[0].clone());

            // Check if we have 4 words (complete IPv4)
            if completed_words.len() == 4 {
                let word_str = completed_words.join(" ");
                match encoder.decode(&word_str) {
                    Ok(decoded) => {
                        println!(
                            "
✅ Complete! {word_str}{decoded}
"
                        );
                        completed_words.clear();
                    }
                    Err(_) => {
                        println!(
                            "
❌ Invalid word combination
"
                        );
                        completed_words.clear();
                    }
                }
            }
        } else {
            println!(
                "
❌ Ambiguous input: {} matches found
",
                hints.len()
            );
        }
    } else {
        println!(
            "
❌ Invalid word or prefix
"
        );
    }

    Ok(false)
}

/// Get the best completion for current input
fn get_best_completion(encoder: &FourWordAdaptiveEncoder, input: &str) -> Option<String> {
    if input.len() >= 3 {
        let hints = encoder.get_word_hints(input);
        if hints.len() == 1 {
            Some(hints[0].clone())
        } else if !hints.is_empty() {
            // Return the shortest match
            hints.into_iter().min_by_key(|s| s.len())
        } else {
            None
        }
    } else {
        None
    }
}

/// Process input as complete IP address or word sequence
#[allow(dead_code)]
fn process_complete_input(
    encoder: &FourWordAdaptiveEncoder,
    input: &str,
    verbose: bool,
) -> Result<Option<String>> {
    // Check if it looks like an IP address or complete word sequence
    if input.contains(':') || input.contains('[') || input.parse::<std::net::IpAddr>().is_ok() {
        // Looks like IP address
        let encoded = encoder.encode(input)?;
        if verbose {
            Ok(Some(format!("{input}{encoded}")))
        } else {
            Ok(Some(encoded))
        }
    } else if looks_like_words(input) {
        // Looks like complete word sequence
        let decoded = encoder.decode(input)?;
        if verbose {
            Ok(Some(format!("{input}{decoded}")))
        } else {
            Ok(Some(decoded))
        }
    } else {
        // Not complete input
        Err(FourWordError::InvalidInput(
            "Not complete input".to_string(),
        ))
    }
}

/// Handle progressive input with autocomplete
#[allow(dead_code)]
fn handle_progressive_input(
    encoder: &FourWordAdaptiveEncoder,
    input: &str,
    current_input: &mut String,
    current_words: &mut Vec<String>,
) {
    current_input.push_str(input);

    // Check for space (word completion)
    if current_input.contains(' ') {
        let parts: Vec<&str> = current_input.split(' ').collect();
        if let Some(word) = parts.first().filter(|w| !w.is_empty()) {
            // Complete the current word
            if let Some(completed) = try_complete_word(encoder, word) {
                current_words.push(completed);
                *current_input = parts[1..].join(" ");

                // Check if we have 4 words (complete IPv4)
                if current_words.len() == 4 {
                    let word_sequence = current_words.join(" ");
                    if let Ok(decoded) = encoder.decode(&word_sequence) {
                        println!("✅ Complete! {word_sequence}{decoded}");
                    }
                    current_words.clear();
                    current_input.clear();
                }
            } else {
                println!("❌ '{word}' is not a valid word. Try again.");
                current_input.clear();
            }
        }
    } else {
        // Show hints for current input
        show_progressive_hints(encoder, current_input);
    }
}

/// Try to complete a partial word
#[allow(dead_code)]
fn try_complete_word(encoder: &FourWordAdaptiveEncoder, partial: &str) -> Option<String> {
    // Auto-complete at 5 characters
    if partial.len() >= 5 {
        return encoder.auto_complete_at_five(partial);
    }

    // Check if it's already a complete word
    let hints = encoder.get_word_hints(partial);
    if hints.len() == 1 && hints[0] == partial {
        return Some(partial.to_string());
    }

    None
}

/// Show progressive hints for current input
#[allow(dead_code)]
fn show_progressive_hints(encoder: &FourWordAdaptiveEncoder, input: &str) {
    if input.len() < 3 {
        return;
    }

    let hints = encoder.get_word_hints(input);
    match hints.len() {
        0 => println!("❌ No words start with '{input}'"),
        1 => {
            if hints[0] == input {
                println!("✅ '{input}' is complete");
            } else {
                println!("💡 Complete: {}", hints[0]);
            }
        }
        2..=5 => {
            println!("💡 Hints: {}", hints.join(", "));
        }
        _ => {
            println!(
                "💡 {} possibilities: {}, ...",
                hints.len(),
                hints[..3].join(", ")
            );
        }
    }
}

/// Show completion hints utility function
fn show_completion_hints(encoder: &FourWordAdaptiveEncoder, prefix: &str) -> Result<()> {
    let hints = encoder.get_word_hints(prefix);
    if hints.is_empty() {
        println!("No words found starting with '{prefix}'");
    } else {
        println!("Completions for '{}' ({} found):", prefix, hints.len());
        for hint in hints.iter().take(10) {
            println!("  {hint}");
        }
        if hints.len() > 10 {
            println!("  ... and {} more", hints.len() - 10);
        }
    }
    Ok(())
}

/// Show validation results utility function
fn show_validation_results(encoder: &FourWordAdaptiveEncoder, partial: &str) -> Result<()> {
    let result = encoder.validate_partial_input(partial)?;

    println!("Validation results for '{partial}':");
    println!("  Valid prefix: {}", result.is_valid_prefix);
    println!("  Words so far: {}", result.word_count_so_far);
    println!("  Is complete: {}", result.is_complete);

    if !result.possible_completions.is_empty() {
        println!("  Completions: {}", result.possible_completions.join(", "));
    }

    Ok(())
}

/// Show help information
#[allow(dead_code)]
fn show_help() {
    println!("🌐 Four-Word Networking Help");
    println!();
    println!("Interactive Mode Commands:");
    println!("  help     - Show this help");
    println!("  clear    - Clear current input");
    println!("  quit     - Exit the program");
    println!();
    println!("Usage:");
    println!("  • Type IP address → get 4 words (IPv4) or 6/9/12 words (IPv6)");
    println!("  • Type words → get IP address");
    println!("  • Progressive hints appear at 3+ characters");
    println!("  • Auto-completion happens at 5+ characters");
    println!("  • Space completes current word and moves to next");
    println!();
    println!("Examples:");
    println!("  192.168.1.1    → four memorable words");
    println!("  about beam cat → reconstructed IP address");
    println!("  ::1            → six words for IPv6 loopback");
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_looks_like_words() {
        // Valid words - 4 words with spaces
        assert!(looks_like_words("ocean thunder falcon star"));

        // Valid words - 6 words with spaces
        assert!(looks_like_words("ocean thunder falcon star book april"));

        // Valid words - 9 words with spaces
        assert!(looks_like_words(
            "ocean thunder falcon star book april wing moon river"
        ));

        // Valid words - 4 words with dots
        assert!(looks_like_words("ocean.thunder.falcon.star"));

        // Invalid - wrong count
        assert!(!looks_like_words("ocean.thunder.falcon"));
        assert!(!looks_like_words("a.b.c.d.e"));

        // Invalid - contains non-alphabetic
        assert!(!looks_like_words("ocean.thunder.123"));
        assert!(!looks_like_words("192.168.1.1"));
        assert!(!looks_like_words("ocean:thunder:falcon"));
    }
}