-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstring_methods.cpp
More file actions
42 lines (32 loc) · 1.74 KB
/
Copy pathstring_methods.cpp
File metadata and controls
42 lines (32 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <string>
#include "catch.hpp"
#include <chaiscript/chaiscript.hpp>
#include "../include/chaiscript/extras/string_methods.hpp"
TEST_CASE( "string_methods functions work", "[string_methods]" ) {
// Create the ChaiScript environment with stdlib available.
chaiscript::ChaiScript chai;
// Add the string_methods module.
auto stringmethods = chaiscript::extras::string_methods::bootstrap();
chai.add(stringmethods);
// replace(string, string)
CHECK(chai.eval<std::string>("\"Hello World!\".replace(\"Hello\", \"Goodbye\")") == "Goodbye World!");
// replace(char, char)
CHECK(chai.eval<std::string>("\"Hello World!\".replace('l', 'r')") == "Herro Worrd!");
// trim()
CHECK(chai.eval<std::string>("\" Hello World! \".trim()") == "Hello World!");
CHECK(chai.eval<std::string>("\" Hello World! \".trimStart()") == "Hello World! ");
CHECK(chai.eval<std::string>("\" Hello World! \".trimEnd()") == " Hello World!");
// split()
CHECK(chai.eval<std::string>("\"Hello,World,How,Are,You\".split(\",\")[1]") == "World");
CHECK(chai.eval<std::string>("split(\"Hello,World,How,Are,You\", \",\")[1]") == "World");
// toLowerCase()
CHECK(chai.eval<std::string>("\"HeLLO WoRLD!\".toLowerCase()") == "hello world!");
// toUpperCase()
CHECK(chai.eval<std::string>("\"Hello World!\".toUpperCase()") == "HELLO WORLD!");
// includes()
CHECK(chai.eval<bool>("\"Hello World!\".includes(\"orl\")") == true);
CHECK(chai.eval<bool>("\"Hello World!\".includes(\"Not Included\")") == false);
CHECK(chai.eval<bool>("\"Hello World!\".includes('l')") == true);
CHECK(chai.eval<bool>("\"Hello World!\".includes('a')") == false);
}