MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / TEST

Function TEST

tests/script_parser_test.cpp:29–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27} // namespace
28
29TEST(ParserTest, AnyTypes)
30{
31 BT::Ast::Environment env = { BT::Blackboard::create(), {} };
32
33 auto Parse = [&env](const char* str) { return BT::ParseScriptAndExecute(env, str); };
34
35 auto result = Parse("628");
36 EXPECT_TRUE(result.has_value());
37 EXPECT_EQ(result.value().cast<int>(), 628);
38
39 result = Parse("-628");
40 EXPECT_TRUE(result.has_value());
41 EXPECT_EQ(result.value().cast<int>(), -628);
42
43 result = Parse("0x100");
44 EXPECT_TRUE(result.has_value());
45 EXPECT_EQ(result.value().cast<int>(), 256);
46
47 result = Parse("0X100");
48 EXPECT_TRUE(result.has_value());
49 EXPECT_EQ(result.value().cast<int>(), 256);
50
51 result = Parse("3.14");
52 EXPECT_TRUE(result.has_value());
53 EXPECT_EQ(result.value().cast<double>(), 3.14);
54
55 result = Parse("-3.14");
56 EXPECT_TRUE(result.has_value());
57 EXPECT_EQ(result.value().cast<double>(), -3.14);
58
59 result = Parse("3.14e2");
60 EXPECT_TRUE(result.has_value());
61 EXPECT_EQ(result.value().cast<double>(), 314);
62
63 result = Parse("3.14e-2");
64 EXPECT_TRUE(result.has_value());
65 EXPECT_EQ(result.value().cast<double>(), 0.0314);
66
67 result = Parse("3e2");
68 EXPECT_TRUE(result.has_value());
69 EXPECT_EQ(result.value().cast<double>(), 300);
70
71 result = Parse("3e-2");
72 EXPECT_TRUE(result.has_value());
73 EXPECT_EQ(result.value().cast<double>(), 0.03);
74
75 result = Parse("'hello world '");
76 EXPECT_TRUE(result.has_value());
77 EXPECT_EQ(result.value().cast<std::string>(), "hello world ");
78
79 result = Parse("true");
80 EXPECT_TRUE(result.has_value());
81 EXPECT_EQ(result.value().cast<int>(), 1);
82
83 result = Parse("false");
84 EXPECT_TRUE(result.has_value());
85 EXPECT_EQ(result.value().cast<int>(), 0);
86}

Callers

nothing calls this directly

Calls 15

createFunction · 0.85
ParseScriptAndExecuteFunction · 0.85
ValidateScriptFunction · 0.85
GetScriptResultFunction · 0.85
PortInfoClass · 0.85
bindFunction · 0.85
InputPortFunction · 0.85
OutputPortFunction · 0.85
RegisterTestTickFunction · 0.85
getKeysMethod · 0.80
createEntryMethod · 0.80
registerScriptingEnumMethod · 0.80

Tested by

no test coverage detected