[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / unittests / Bitstream / BitstreamWriterTest.cpp
blob993c5aadee2d4fb0a9ac057bd19f1f4a9271463d
1 //===- BitstreamWriterTest.cpp - Tests for BitstreamWriter ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Bitstream/BitstreamWriter.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace {
18 TEST(BitstreamWriterTest, emitBlob) {
19 SmallString<64> Buffer;
20 BitstreamWriter W(Buffer);
21 W.emitBlob("str", /* ShouldEmitSize */ false);
22 EXPECT_EQ(StringRef("str\0", 4), Buffer);
25 TEST(BitstreamWriterTest, emitBlobWithSize) {
26 SmallString<64> Buffer;
28 BitstreamWriter W(Buffer);
29 W.emitBlob("str");
31 SmallString<64> Expected;
33 BitstreamWriter W(Expected);
34 W.EmitVBR(3, 6);
35 W.FlushToWord();
36 W.Emit('s', 8);
37 W.Emit('t', 8);
38 W.Emit('r', 8);
39 W.Emit(0, 8);
41 EXPECT_EQ(StringRef(Expected), Buffer);
44 TEST(BitstreamWriterTest, emitBlobEmpty) {
45 SmallString<64> Buffer;
46 BitstreamWriter W(Buffer);
47 W.emitBlob("", /* ShouldEmitSize */ false);
48 EXPECT_EQ(StringRef(""), Buffer);
51 TEST(BitstreamWriterTest, emitBlob4ByteAligned) {
52 SmallString<64> Buffer;
53 BitstreamWriter W(Buffer);
54 W.emitBlob("str0", /* ShouldEmitSize */ false);
55 EXPECT_EQ(StringRef("str0"), Buffer);
58 } // end namespace