mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Add RawStringOstream for slightly simpler streaming to strings (#4817)
This adds a RawStringOstream. Versus TestRawOstream, which is
consolidated over to RawStringOstream, it uses a string for storage
instead of a vector, mainly to support move-to-string semantics. Versus
llvm::raw_string_ostream, it owns the string and supports pwrite (which
is needed for driver and its fd_ostream compatibility requirement).
This converts most uses of llvm::raw_string_ostream, leaving behind a
few in InstNamer that explicitly cannot own the string, such as:
```
llvm::raw_string_ostream(name)
<< "_" << tree.tokens().GetColumnNumber(token);
```
I have this as its own library so that it can use CHECK.
Yes this doesn't save much code, but it's code we repeatedly write.
---------
Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Geoff Romer
parent
ef6e035e7d
commit
4c4c4a4d2c
@@ -7,7 +7,7 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "testing/base/test_raw_ostream.h"
|
||||
#include "common/raw_string_ostream.h"
|
||||
#include "toolchain/testing/yaml_test_helpers.h"
|
||||
|
||||
namespace Carbon::Testing {
|
||||
@@ -31,7 +31,7 @@ auto MatchSharedValues(testing::Matcher<Yaml::MappingValue> ints,
|
||||
|
||||
TEST(SharedValueStores, PrintEmpty) {
|
||||
SharedValueStores value_stores;
|
||||
TestRawOstream out;
|
||||
RawStringOstream out;
|
||||
value_stores.Print(out);
|
||||
EXPECT_THAT(Yaml::Value::FromText(out.TakeStr()),
|
||||
MatchSharedValues(IsEmpty(), IsEmpty(), IsEmpty(), IsEmpty()));
|
||||
@@ -46,7 +46,7 @@ TEST(SharedValueStores, PrintVals) {
|
||||
Real{.mantissa = apint, .exponent = apint, .is_decimal = true});
|
||||
value_stores.identifiers().Add("a");
|
||||
value_stores.string_literal_values().Add("foo'\"baz");
|
||||
TestRawOstream out;
|
||||
RawStringOstream out;
|
||||
value_stores.Print(out);
|
||||
|
||||
EXPECT_THAT(Yaml::Value::FromText(out.TakeStr()),
|
||||
|
||||
Reference in New Issue
Block a user