Skip to content

Commit 23f0243

Browse files
authored
Merge pull request #8 from atom-community/fix-cpp-tests
2 parents 90bc20c + b6d50ee commit 23f0243

File tree

7 files changed

+2245
-1086
lines changed

7 files changed

+2245
-1086
lines changed

benchmark/native/marker-index-benchmark.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using namespace std::chrono;
1111
using std::vector;
12+
using uint = unsigned int;
1213

1314
Range get_random_range() {
1415
Point start(rand() % 100, rand() % 100);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:node": "node-gyp rebuild",
99
"build:browser": "bash -c script/build-browser-version.sh || echo 'the browser build is unsupported'",
1010
"build": "npm run build:node && npm run build:browser",
11-
"test:native": "node ./script/test-native.js",
11+
"test:native": "node-gyp build --debug --tests && node script/test-native.js",
1212
"test:node": "mocha test/js/*.js",
1313
"test:browser": "cross-env SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js || echo 'the browser tests are unsupported'",
1414
"test": "npm run test:node && npm run test:native && npm run test:browser",

script/test-native.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ switch (args[0]) {
5252
}
5353

5454
function run(command, args = [], options = {stdio: 'inherit'}) {
55-
const {status} = spawnSync(command, args, options)
56-
if (status !== 0) process.exit(status)
57-
}
55+
spawnSync(command, args, options)
56+
}

test/native/encoding-conversion-test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using std::u16string;
1010

1111
TEST_CASE("EncodingConversion::decode - basic UTF-8") {
1212
auto conversion = transcoding_from("UTF-8");
13-
string input("abγdefg\nhijklmnop");
13+
string input(u8"abγdefg\nhijklmnop");
1414

1515
u16string string;
1616
conversion->decode(string, input.data(), input.size());
@@ -42,7 +42,7 @@ TEST_CASE("EncodingConversion::decode - invalid byte sequences in the middle of
4242

4343
u16string string;
4444
conversion->decode(string, input.data(), input.size());
45-
REQUIRE(string == u"ab" "\ufffd" "\ufffd" "de");
45+
REQUIRE(string == u"ab" u"\ufffd" u"\ufffd" u"de");
4646
}
4747

4848
TEST_CASE("EncodingConversion::decode - invalid byte sequences at the end of the input") {
@@ -58,7 +58,7 @@ TEST_CASE("EncodingConversion::decode - invalid byte sequences at the end of the
5858
string.clear();
5959
bytes_encoded = conversion->decode(string, input.data(), input.size(), true);
6060
REQUIRE(bytes_encoded == 4);
61-
REQUIRE(string == u"ab" "\ufffd" "\ufffd");
61+
REQUIRE(string == u"ab" u"\ufffd" u"\ufffd");
6262
}
6363

6464
TEST_CASE("EncodingConversion::decode - four-byte UTF-16 characters") {
@@ -67,7 +67,7 @@ TEST_CASE("EncodingConversion::decode - four-byte UTF-16 characters") {
6767

6868
u16string string;
6969
conversion->decode(string, input.data(), input.size());
70-
REQUIRE(string == u"ab" "\xd83d" "\xde01" "cd");
70+
REQUIRE(string == u"ab" u"\xd83d" u"\xde01" u"cd");
7171
}
7272

7373
TEST_CASE("EncodingConversion::encode - basic") {
@@ -93,7 +93,7 @@ TEST_CASE("EncodingConversion::encode - basic") {
9393

9494
TEST_CASE("EncodingConversion::encode - four-byte UTF-16 characters") {
9595
auto conversion = transcoding_to("UTF-8");
96-
u16string string = u"ab" "\xd83d" "\xde01" "cd"; // 'ab😁cd'
96+
u16string string = u"ab" u"\xd83d" u"\xde01" u"cd"; // 'ab😁cd'
9797

9898
vector<char> output(10);
9999
size_t bytes_encoded = 0, start = 0;
@@ -116,32 +116,32 @@ TEST_CASE("EncodingConversion::encode - four-byte UTF-16 characters") {
116116

117117
TEST_CASE("EncodingConversion::encode - invalid characters in the middle of the string") {
118118
auto conversion = transcoding_to("UTF-8");
119-
u16string string = u"abc" "\xD800" "def";
119+
u16string string = u"abc" u"\xD800" u"def";
120120

121121
vector<char> output(10);
122122
size_t bytes_encoded = 0, start = 0;
123123

124124
bytes_encoded = conversion->encode(
125125
string, &start, string.size(), output.data(), output.size());
126-
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd" "def");
126+
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd" u8"def");
127127

128128
// Here, the invalid character occurs at the end of a chunk.
129129
start = 0;
130130
bytes_encoded = conversion->encode(
131131
string, &start, 4, output.data(), output.size());
132132
bytes_encoded += conversion->encode(
133133
string, &start, string.size(), output.data() + bytes_encoded, output.size() - bytes_encoded);
134-
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd" "def");
134+
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd" u8"def");
135135
}
136136

137137
TEST_CASE("EncodingConversion::encode - invalid characters at the end of the string") {
138138
auto conversion = transcoding_to("UTF-8");
139-
u16string string = u"abc" "\xD800";
139+
u16string string = u"abc" u"\xD800";
140140

141141
vector<char> output(10);
142142
size_t bytes_encoded = 0, start = 0;
143143

144144
bytes_encoded = conversion->encode(
145145
string, &start, string.size(), output.data(), output.size(), true);
146-
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd");
146+
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd");
147147
}

test/native/test-helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using std::cout;
1717
using std::cerr;
18+
using uint = unsigned int;
1819

1920
class TextBuffer;
2021

test/native/text-buffer-test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "text-slice.h"
55
#include "regex.h"
66
#include <future>
7-
#include <unistd.h>
7+
#include <chrono>
8+
#include <thread>
89

910
using std::move;
1011
using std::pair;
@@ -466,7 +467,7 @@ TEST_CASE("TextBuffer::find_words_with_subsequence_in_range") {
466467
}
467468

468469
TEST_CASE("TextBuffer::has_astral") {
469-
REQUIRE(TextBuffer{u"ab" "\xd83d" "\xde01" "cd"}.has_astral());
470+
REQUIRE(TextBuffer{u"ab" u"\xd83d" u"\xde01" u"cd"}.has_astral());
470471
REQUIRE(!TextBuffer{u"abcd"}.has_astral());
471472
}
472473

@@ -535,7 +536,7 @@ TEST_CASE("TextBuffer - random edits and queries") {
535536
Generator rand(seed);
536537
vector<SnapshotData> results;
537538
for (uint32_t k = 0; k < 5; k++) {
538-
usleep(rand() % 1000);
539+
std::this_thread::sleep_for(std::chrono::microseconds(rand() % 1000));
539540
vector<Point> line_ending_positions;
540541
for (uint32_t row = 0; row < snapshot->extent().row; row++) {
541542
line_ending_positions.push_back({row, snapshot->line_length_for_row(row)});

0 commit comments

Comments
 (0)