|
| 1 | +use unilang::prelude::*; |
| 2 | +use unilang::ValidationRule; |
| 3 | +use unilang_parser::{ Parser, UnilangParserOptions }; |
| 4 | + |
| 5 | +#[ test ] |
| 6 | +fn arg_list_test() -> Result< (), unilang::Error > |
| 7 | +{ |
| 8 | + let mut registry = CommandRegistry::new(); |
| 9 | + |
| 10 | + let arg = ArgumentDefinition::former() |
| 11 | + .description( "Defines hex to place a castle to." ) |
| 12 | + .name( "coord" ) |
| 13 | + .hint( "" ) |
| 14 | + .aliases( vec![] ) |
| 15 | + .tags( vec![] ) |
| 16 | + .kind( Kind::List( Box::new( Kind::Integer ), None ) ) |
| 17 | + .validation_rules( vec![ ValidationRule::MinItems( 2 ) ] ) |
| 18 | + .end(); |
| 19 | + |
| 20 | + let buy_castle_def = CommandDefinition::former() |
| 21 | + .name( ".buy_castle" ) |
| 22 | + .namespace( ".region" ) |
| 23 | + .hint( "Puts a castle to hex" ) |
| 24 | + .status( "stable" ) |
| 25 | + .version( "1.0.0" ) |
| 26 | + .arguments( vec![ arg ] ) |
| 27 | + .end(); |
| 28 | + |
| 29 | + let routine = Box::new |
| 30 | + ( |
| 31 | + | _cmd, _ctx | |
| 32 | + { |
| 33 | + Ok |
| 34 | + ( |
| 35 | + OutputData |
| 36 | + { |
| 37 | + content : "".to_string(), |
| 38 | + format : "".to_string(), |
| 39 | + } |
| 40 | + ) |
| 41 | + } |
| 42 | + ); |
| 43 | + registry.command_add_runtime( &buy_castle_def, routine )?; |
| 44 | + |
| 45 | + let parser = Parser::new( UnilangParserOptions::default() ); |
| 46 | + |
| 47 | + let input = ".region.buy_castle 1 1"; |
| 48 | + let instructions = [ parser.parse_single_instruction( input ).map_err( unilang::Error::from )? ]; |
| 49 | + let semantic_analyzer = unilang::semantic::SemanticAnalyzer::new( &instructions[ .. ], ®istry ); |
| 50 | + let commands = semantic_analyzer.analyze()?; |
| 51 | + let interpreter = unilang::interpreter::Interpreter::new( &commands, ®istry ); |
| 52 | + let mut context = unilang::interpreter::ExecutionContext::default(); |
| 53 | + interpreter.run( &mut context )?; |
| 54 | + |
| 55 | + Ok( () ) |
| 56 | +} |
0 commit comments