Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_syntax/tests/core.rs

2.1 KiB, 15 runs

created by r1870400018:1059, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_syntax::{
2 arg::{
3 Arg,
4 ArgConfig,
5 },
6 cmd::{
7 Cmd,
8 CmdConfig,
9 },
10 core::{
11 Syntax,
12 SyntaxConfig,
13 },
14 key::Key,
15};
16
17use oxedyne_fe2o3_core::{
18 prelude::*,
19 map::MapRec,
20 test::test_it,
21};
22use oxedyne_fe2o3_jdat::{
23 prelude::*,
24 version::SemVer,
25};
26
27pub fn test_core(filter: &'static str) -> Outcome<()> {
28
29 res!(test_it(filter, &["Arg value", "all", "arg"], || {
30 let arg = Arg::from(ArgConfig {
31 name: fmt!("test"),
32 vals: vec![(Kind::C64, fmt!("A test kind.")).into()],
33 ..Default::default()
34 });
35 req!(arg.config().vals.len(), 1);
36 req!(arg.config().vals[0].kind, Kind::C64);
37 Ok(())
38 }));
39
40 res!(test_it(filter, &["Set retrieve", "all", "arg"], || {
41 let mut p = Syntax::from(SyntaxConfig {
42 name: fmt!("TestSyntax"),
43 ver: SemVer::new(0, 1, 0),
44 about: Some(fmt!("Testing")),
45 ..Default::default()
46 });
47 let mut c = Cmd::from(CmdConfig {
48 name: fmt!("print"),
49 help: Some(fmt!("Execute printing")),
50 ..Default::default()
51 });
52 let a = Arg::from(ArgConfig {
53 name: fmt!("colour"),
54 hyph1: Some(fmt!("c")),
55 hyph2: Some(fmt!("c")),
56 reqd: false,
57 help: Some(fmt!("Use colour")),
58 ..Default::default()
59 });
60 c = res!(c.add_arg(a));
61 p = res!(p.add_cmd(c));
62
63 req!(p.config().name, "TestSyntax".to_string());
64 req!(p.config().ver, SemVer::new(0, 1, 0));
65 req!(p.config().about, Some("Testing".to_string()));
66
67 if let Some(cmd) = p.cmds.get_recursive(&Key::from("print")) {
68 if let Some(arg) = cmd.args.get_recursive(&Key::from("colour")) {
69 req!(arg.config().hyph1, Some(fmt!("c")));
70 } else {
71 panic!("Could not find the argument 'colour'");
72 }
73 } else {
74 panic!("Could not find the command 'print'");
75 }
76 Ok(())
77 }));
78
79 Ok(())
80}