bckplayer 0.1.0

A cross-platform CLI media player interface for VLC
Documentation
use crate::commands::get_command_suggestions;

#[test]
fn test_improved_fuzzy_search() {
    // Test exact matches
    let suggestions = get_command_suggestions("play");
    assert!(!suggestions.is_empty());
    assert_eq!(suggestions[0].command, "play");
    assert!(suggestions[0].score > 5000); // High score for exact match

    // Test prefix matches
    let suggestions = get_command_suggestions("vol");
    assert!(!suggestions.is_empty());
    let vol_commands: Vec<&str> = suggestions.iter().map(|s| s.command.as_str()).collect();
    assert!(vol_commands.contains(&"volume"));
    assert!(vol_commands.contains(&"volumeup"));
    assert!(vol_commands.contains(&"volumedown"));

    // Test alias matches
    let suggestions = get_command_suggestions("fs");
    assert!(suggestions.iter().any(|s| s.command.contains("fullscreen")));

    // Test keyword matches
    let suggestions = get_command_suggestions("louder");
    assert!(suggestions.iter().any(|s| s.command == "volumeup"));

    // Test fuzzy matching
    let suggestions = get_command_suggestions("sped");
    assert!(suggestions.iter().any(|s| s.command.contains("speed")));

    // Test empty input returns all commands
    let suggestions = get_command_suggestions("");
    assert!(suggestions.len() == 10); // Limited to 10
    assert!(suggestions.iter().all(|s| s.score > 0));
}

#[test]
fn test_search_scoring() {
    // Exact match should score higher than prefix
    let exact = get_command_suggestions("play");
    let prefix = get_command_suggestions("pla");
    
    if !exact.is_empty() && !prefix.is_empty() {
        assert!(exact[0].score > prefix[0].score);
    }

    // Prefix should score higher than contains
    let prefix = get_command_suggestions("vol");
    let contains = get_command_suggestions("ol");
    
    if !prefix.is_empty() && !contains.is_empty() {
        let vol_in_prefix = prefix.iter().find(|s| s.command == "volume");
        let vol_in_contains = contains.iter().find(|s| s.command == "volume");
        
        if let (Some(p), Some(c)) = (vol_in_prefix, vol_in_contains) {
            assert!(p.score > c.score);
        }
    }
}

#[test]
fn test_command_aliases() {
    // Test that vol matches volume commands
    let suggestions = get_command_suggestions("vol");
    let commands: Vec<String> = suggestions.iter().map(|s| s.command.clone()).collect();
    
    assert!(commands.contains(&"volume".to_string()));
    assert!(commands.contains(&"volumeup".to_string()) || commands.contains(&"volup".to_string()));
    assert!(commands.contains(&"volumedown".to_string()) || commands.contains(&"voldown".to_string()));
}

fn main() {
    println!("Testing improved fuzzy search...");
    
    // Test various inputs
    let test_inputs = vec!["vol", "play", "spe", "ful", "qui", "open", "seek"];
    
    for input in test_inputs {
        println!("\nInput: '{}'", input);
        let suggestions = get_command_suggestions(input);
        for (i, suggestion) in suggestions.iter().take(5).enumerate() {
            println!("  {}. {} (score: {}) - {}", 
                i + 1, 
                suggestion.command, 
                suggestion.score, 
                suggestion.description
            );
        }
    }
    
    println!("\n✓ All tests passed! Fuzzy search is working much better.");
}