-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstring_methods.cpp
More file actions
35 lines (26 loc) · 1.31 KB
/
string_methods.cpp
File metadata and controls
35 lines (26 loc) · 1.31 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
#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 <chaiscript/chaiscript_stdlib.hpp>
#include "../include/chaiscript/extras/string_methods.hpp"
TEST_CASE( "string_methods functions work", "[string_methods]" ) {
auto stdlib = chaiscript::Std_Lib::library();
chaiscript::ChaiScript chai(stdlib);
// Add the string_methods module.
auto stringmethods = chaiscript::extras::string_methods::bootstrap();
chai.add(chaiscript::bootstrap::standard_library::vector_type<std::vector<std::string>>("StringVector"));
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('e', 'i')") == "Hillo World!");
// trim()
CHECK(chai.eval<std::string>("\" Hello World! \".trim()") == "Hello World!");
// split()
CHECK(chai.eval<std::string>("\"Hello,World,How,Are,You\".split(\",\")[1]") == "World");
// toLowerCase()
CHECK(chai.eval<std::string>("\"HeLLO WoRLD!\".toLowerCase()") == "hello world!");
// toUpperCase()
CHECK(chai.eval<std::string>("\"Hello World!\".toUpperCase()") == "HELLO WORLD!");
}