use super::*;
use crate::generator::parser::command::argument::minecraft::MinecraftTimeUnit;
use std::iter::FromIterator;
#[test]
fn test_say() {
let parser = CommandParser::default().unwrap();
let line = "say execute as @e run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([(15, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_tellraw() {
let parser = CommandParser::default().unwrap();
let line = r#"tellraw @a {"text":"Hello World!"}"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual.0,
Line::OtherCommand {
selectors: BTreeMap::from_iter([(8, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
}
);
}
#[test]
fn test_scoreboard_objectives_add() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard objectives add test_score dummy";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test_score".to_string()]),
},
None
)
);
}
#[test]
fn test_scoreboard_objectives_setdisplay() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard objectives setdisplay sidebar test_score";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test_score".to_string()]),
},
None
)
);
}
#[test]
fn test_scoreboard_set_objectives() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard players set test test_score 5";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test_score".to_string()]),
},
None
)
);
}
#[test]
fn test_scoreboard_reset_objectives() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard players reset * test";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test".to_string()]),
},
None
)
);
}
#[test]
fn test_scoreboard_operation_selectors() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard players operation @s test = @e[tag=test] test";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([
(29, SelectorValue::empty_self()),
(39, SelectorValue::default())
]),
objectives: BTreeSet::from_iter(["test".to_string()]),
},
None
)
);
}
#[test]
fn test_scoreboard_operation_names() {
let parser = CommandParser::default().unwrap();
let line = "scoreboard players operation var1 test = var2 test";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test".to_string()]),
},
None
)
);
}
#[test]
fn test_execute() {
let parser = CommandParser::default().unwrap();
let line = "execute run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 12,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_align() {
let parser = CommandParser::default().unwrap();
let line = "execute align xyz run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 22,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_anchored() {
let parser = CommandParser::default().unwrap();
let line = "execute anchored eyes run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 26,
name: ResourceLocation::new("test", "func"),
anchor: Some(MinecraftEntityAnchor::Eyes),
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_multiple_anchored() {
let parser = CommandParser::default().unwrap();
let line = "execute anchored feet anchored eyes run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 40,
name: ResourceLocation::new("test", "func"),
anchor: Some(MinecraftEntityAnchor::Eyes),
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_multiple_execute_anchored() {
let parser = CommandParser::default().unwrap();
let line = "execute anchored feet run execute anchored eyes run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 52,
name: ResourceLocation::new("test", "func"),
anchor: Some(MinecraftEntityAnchor::Eyes),
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_multiple_execute_some_anchored() {
let parser = CommandParser::default().unwrap();
let line = "execute anchored eyes run execute as @s run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 44,
name: ResourceLocation::new("test", "func"),
anchor: Some(MinecraftEntityAnchor::Eyes),
selectors: BTreeMap::from_iter([(37, SelectorValue::empty_self())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_as() {
let parser = CommandParser::default().unwrap();
let line = "execute as @e[type=area_effect_cloud] run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 42,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(11, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_at() {
let parser = CommandParser::default().unwrap();
let line = "execute at @e[type=area_effect_cloud] run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 42,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(11, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_facing_pos() {
let parser = CommandParser::default().unwrap();
let line = "execute facing 1 ~2 -3 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 27,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_facing_entity() {
let parser = CommandParser::default().unwrap();
let line = "execute facing entity @e[type=area_effect_cloud] eyes run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 58,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(22, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_in() {
let parser = CommandParser::default().unwrap();
let line = "execute in the_nether run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 26,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_in_qualified() {
let parser = CommandParser::default().unwrap();
let line = "execute in minecraft:the_end run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 33,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_on() {
let parser = CommandParser::default().unwrap();
let line = "execute on attacker run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 24,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_positioned_absolute() {
let parser = CommandParser::default().unwrap();
let line = "execute positioned -1 0 1 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 30,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_positioned_local() {
let parser = CommandParser::default().unwrap();
let line = "execute positioned ^-1 ^.3 ^-4.5 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 37,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_positioned_relative() {
let parser = CommandParser::default().unwrap();
let line = "execute positioned ~-1 ~.3 ~-4.5 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 37,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_positioned_as() {
let parser = CommandParser::default().unwrap();
let line = "execute positioned as @e[type=area_effect_cloud] run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 53,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(22, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_positioned_over() {
let parser = CommandParser::default().unwrap();
let line = "execute positioned over world_surface run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 42,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_rotated_absolute() {
let parser = CommandParser::default().unwrap();
let line = "execute rotated 1 -5 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 25,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_rotated_relative() {
let parser = CommandParser::default().unwrap();
let line = "execute rotated ~ ~-.5 run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 27,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_rotated_as() {
let parser = CommandParser::default().unwrap();
let line = "execute rotated as @e[type=area_effect_cloud] run function test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 50,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(19, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_biome() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if biome ~ ~ ~ minecraft:forest run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 44,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_biome_without_namespace() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if biome ~ ~ ~ forest run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 34,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_biome_tag() {
let parser = CommandParser::default().unwrap();
let line =
r#"execute if biome ~ ~ ~ #minecraft:allows_surface_slime_spawns run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 66,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_biome_tag_without_namespace() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if biome ~ ~ ~ #allows_surface_slime_spawns run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 56,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_block() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if block ^1 ^.25 ^-.75 chest[facing=east]{Items:[{id:"minecraft:apple",Slot:13b,Count:1b}]} run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 104,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_block_tag() {
let parser = CommandParser::default().unwrap();
let line =
r#"execute if block ^1 ^.25 ^-.75 #minecraft:stairs[facing=east] run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 66,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_blocks() {
let parser = CommandParser::default().unwrap();
let line =
r#"execute if blocks -0 ~-.3 ~5 ^1 ^.25 ^-.75 ~-1 ~.5 ~-.75 all run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 65,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_data_block() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if data block 1 2 3 Items[{Slot:13b}] run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 50,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_data_entity() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if data entity @p Inventory[0].tag.BlockEntityTag.Command run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 70,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(23, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_data_storage() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if data storage test foo.bar[0][0].baz run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 51,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_dimension() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if dimension minecraft:overworld run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 45,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_dimension_without_namespace() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if dimension overworld run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 35,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_entity() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if entity @e[type=area_effect_cloud] run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 49,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(18, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_loaded() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if loaded 1 2 3 run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 28,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_predicate() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if predicate mcfd:test_pred run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 40,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_if_score() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if score max test_global >= #min test_global run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 57,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test_global".to_string()]),
},
None
)
);
}
#[test]
fn test_execute_if_score_matches() {
let parser = CommandParser::default().unwrap();
let line = r#"execute if score * test_global matches 0.. run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 47,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter(["test_global".to_string()]),
},
None
)
);
}
#[test]
fn test_execute_store_block() {
let parser = CommandParser::default().unwrap();
let line = r#"execute store success block 1 2 3 Items[0].Count byte 10 run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 61,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_store_bossbar() {
let parser = CommandParser::default().unwrap();
let line = r#"execute store result bossbar test value run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 44,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_store_entity() {
let parser = CommandParser::default().unwrap();
let line = r#"execute store success entity @e[type=minecraft:chest_minecart,sort=nearest,limit=1] Items[{id:"minecraft:apple"}].Count byte 10 run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 132,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(29, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_store_score() {
let parser = CommandParser::default().unwrap();
let line = r#"execute store success score @s test_global run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 47,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([(28, SelectorValue::empty_self())]),
objectives: BTreeSet::from_iter(["test_global".to_string()]),
},
None
)
);
}
#[test]
fn test_execute_store_storage() {
let parser = CommandParser::default().unwrap();
let line = r#"execute store result storage :test my_result long -.5 run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 58,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_summon() {
let parser = CommandParser::default().unwrap();
let line = r#"execute summon sheep run function test:func"#;
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::FunctionCall {
column_index: 25,
name: ResourceLocation::new("test", "func"),
anchor: None,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_kill_selector() {
let parser = CommandParser::default().unwrap();
let line = "kill @s";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([(5, SelectorValue::empty_self())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_kill_self() {
let parser = CommandParser::default().unwrap();
let line = "kill";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OptionalSelectorCommand {
missing_selector: 4,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_schedule() {
let parser = CommandParser::default().unwrap();
let line = "schedule function test:func 1t";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 0,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Replace {
time: MinecraftTime {
time: 1f32,
unit: MinecraftTimeUnit::Tick
}
},
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_schedule_append() {
let parser = CommandParser::default().unwrap();
let line = "schedule function test:func 1t append";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 0,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Append {
time: MinecraftTime {
time: 1f32,
unit: MinecraftTimeUnit::Tick
}
},
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_schedule_clear() {
let parser = CommandParser::default().unwrap();
let line = "schedule clear test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 0,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Clear,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_schedule_replace() {
let parser = CommandParser::default().unwrap();
let line = "schedule function test:func 1t replace";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 0,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Replace {
time: MinecraftTime {
time: 1f32,
unit: MinecraftTimeUnit::Tick
}
},
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_schedule() {
let parser = CommandParser::default().unwrap();
let line = "execute at @e[type=area_effect_cloud] run schedule function test:func 1t";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 42,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Replace {
time: MinecraftTime {
time: 1f32,
unit: MinecraftTimeUnit::Tick
}
},
selectors: BTreeMap::from_iter([(11, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_execute_schedule_clear() {
let parser = CommandParser::default().unwrap();
let line = "execute at @e[type=area_effect_cloud] run schedule clear test:func";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::Schedule {
schedule_start: 42,
function: ResourceLocation::new("test", "func"),
operation: ScheduleOperation::Clear,
selectors: BTreeMap::from_iter([(11, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_team_join_selector() {
let parser = CommandParser::default().unwrap();
let line = "team join Foo @s";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([(14, SelectorValue::empty_self())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_team_join_self() {
let parser = CommandParser::default().unwrap();
let line = "team join Foo";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OptionalSelectorCommand {
missing_selector: 13,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_teleport_location_self() {
let parser = CommandParser::default().unwrap();
let line = "teleport ~ ~5 ~";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OptionalSelectorCommand {
missing_selector: 8,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_teleport_location_selector() {
let parser = CommandParser::default().unwrap();
let line = "teleport @s ~ ~5 ~";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([(9, SelectorValue::empty_self())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_tp_location_self() {
let parser = CommandParser::default().unwrap();
let line = "tp ~ ~5 ~";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OptionalSelectorCommand {
missing_selector: 2,
selectors: BTreeMap::from_iter([]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_teleport_destination_self() {
let parser = CommandParser::default().unwrap();
let line = "teleport @e[type=sheep,limit=1]";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OptionalSelectorCommand {
missing_selector: 8,
selectors: BTreeMap::from_iter([(9, SelectorValue::default())]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}
#[test]
fn test_teleport_destination_selector() {
let parser = CommandParser::default().unwrap();
let line = "teleport @s @e[type=sheep,limit=1]";
let actual = parse_line_internal(&parser, line);
assert_eq!(
actual,
(
Line::OtherCommand {
selectors: BTreeMap::from_iter([
(9, SelectorValue::empty_self()),
(12, SelectorValue::default())
]),
objectives: BTreeSet::from_iter([]),
},
None
)
);
}