forked from 0xShug0/audio.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_partial_text_render.cpp
More file actions
57 lines (46 loc) · 2.02 KB
/
Copy pathtest_partial_text_render.cpp
File metadata and controls
57 lines (46 loc) · 2.02 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "../../app/cli/partial_render.h"
#include "test_assert.h"
#include <exception>
#include <iostream>
#include <string>
namespace {
using engine::test::require_eq;
using minitts::cli::PartialTextRenderer;
// Partials carry only the text decoded since the last one, so a terminal appends them unlabelled
// and the transcript reads as running text.
void test_terminal_appends_partials_verbatim() {
PartialTextRenderer renderer(true);
require_eq(renderer.render(" Some"), std::string(" Some"), "first partial");
require_eq(renderer.render(" call"), std::string(" call"), "second partial");
require_eq(renderer.render(" me"), std::string(" me"), "third partial");
}
// Redirected output keeps the labelled line-per-update format so pipes and logs stay parseable.
void test_redirected_output_keeps_labelled_lines() {
PartialTextRenderer renderer(false);
require_eq(renderer.render(" Some"), std::string("partial_text= Some\n"), "first piped partial");
require_eq(renderer.render(" call"), std::string("partial_text= call\n"), "second piped partial");
}
void test_finish_closes_only_an_open_line() {
PartialTextRenderer opened(true);
opened.render(" Some");
require_eq(opened.finish(), std::string("\n"), "open line is closed");
require_eq(opened.finish(), std::string(""), "line is closed only once");
PartialTextRenderer untouched(true);
require_eq(untouched.finish(), std::string(""), "a run with no partials prints no blank line");
PartialTextRenderer piped(false);
piped.render(" Some");
require_eq(piped.finish(), std::string(""), "piped output already ends its lines");
}
} // namespace
int main() {
try {
test_terminal_appends_partials_verbatim();
test_redirected_output_keeps_labelled_lines();
test_finish_closes_only_an_open_line();
} catch (const std::exception & error) {
std::cerr << "partial_text_render_test failed: " << error.what() << '\n';
return 1;
}
std::cout << "partial_text_render_test passed\n";
return 0;
}