Skip to content

Commit eb8e960

Browse files
committed
update formatting
1 parent e6b3cb2 commit eb8e960

File tree

3 files changed

+87
-15
lines changed

3 files changed

+87
-15
lines changed

source/mir/bignum/internal/dec2float.d

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ private template bigSize(T)
284284
{
285285
enum size_t bits = T.max_exp - T.min_exp + T.mant_dig;
286286
enum size_t bigSize = bits / 64 + bits % 64 + 1;
287-
pragma(msg, "bigSize = ", bigSize);
288287
}
289288
}
290289

source/mir/format.d

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ struct HexAddress(T)
334334
}
335335
}
336336

337+
///ditto
338+
HexAddress!T hexAddress(T)(const T value, SwitchLU switchLU = SwitchLU.upper)
339+
if (isUnsigned!T && !is(T == enum))
340+
{
341+
return typeof(return)(value, switchLU);
342+
}
343+
337344
/++
338345
Escaped string formats
339346
+/
@@ -640,25 +647,37 @@ version (mir_test) unittest
640647

641648
/// Prints array
642649
pragma(inline, false)
643-
ref W print(C = char, W, T)(scope return ref W w, scope const(T)[] c)
650+
ref W printArray(C = char, W, T)(scope return ref W w,
651+
scope const(T)[] c,
652+
scope const(C)[] lb = "[",
653+
scope const(C)[] rb = "]",
654+
scope const(C)[] sep = ", ",
655+
)
644656
if (isSomeChar!C && !isSomeChar!T)
645657
{
646-
enum C left = '[';
647-
enum C right = ']';
648-
enum C[2] sep = ", ";
649-
w.put(left);
658+
w.put(lb);
650659
bool first = true;
651660
foreach (ref e; c)
652661
{
653662
if (!first)
654-
w.printStaticString!C(sep);
663+
w.put(sep);
655664
first = false;
656665
printElement!C(w, e);
657666
}
658-
w.put(right);
667+
w.put(rb);
659668
return w;
660669
}
661670

671+
/// ditto
672+
pragma(inline, false)
673+
ref W print(C = char, W, T)(scope return ref W w,
674+
scope const(T)[] c,
675+
)
676+
if (isSomeChar!C && !isSomeChar!T)
677+
{
678+
return printArray(w, c);
679+
}
680+
662681
///
663682
@safe pure nothrow @nogc
664683
version (mir_test) unittest
@@ -669,6 +688,39 @@ version (mir_test) unittest
669688
assert(w.print(array[]).data == `["a\na", "b"]`);
670689
}
671690

691+
/// Prints array as hex values
692+
pragma(inline, false)
693+
ref W printHexArray(C = char, W, T)(scope return ref W w,
694+
scope const(T)[] c,
695+
scope const(C)[] lb = "",
696+
scope const(C)[] rb = "",
697+
scope const(C)[] sep = " ",
698+
)
699+
if (isSomeChar!C && !isSomeChar!T && isUnsigned!T)
700+
{
701+
w.put(lb);
702+
bool first = true;
703+
foreach (ref e; c)
704+
{
705+
if (!first)
706+
w.put(sep);
707+
first = false;
708+
printElement!C(w, e.hexAddress);
709+
}
710+
w.put(rb);
711+
return w;
712+
}
713+
714+
///
715+
@safe pure nothrow @nogc
716+
version (mir_test) unittest
717+
{
718+
import mir.appender: scopedBuffer;
719+
auto w = scopedBuffer!char;
720+
ubyte[2] array = [0x34, 0x32];
721+
assert(w.print(array[]).data == `34 32`);
722+
}
723+
672724
/// Prints escaped character in the form `'c'`.
673725
pragma(inline, false)
674726
ref W print(C = char, W)(scope return ref W w, char c)

source/mir/test.d

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ struct Should(T)
6565
///
6666
T value;
6767

68-
///
68+
static if(!is(immutable T == immutable ubyte[]))
69+
///
6970
void opEquals(R)(const R expected, string file = __FILE__, int line = __LINE__)
7071
{
7172
import mir.format: stringBuf, getData;
@@ -77,12 +78,29 @@ struct Should(T)
7778
if (value == expected)
7879
return;
7980
auto buf = stringBuf;
80-
assumeAllAttrAndCall({
81-
throw new MirError(buf
82-
<< "expected " << expected
83-
<< ", got " << value
84-
<< getData, file, line);
85-
});
81+
buf << "mir.test.should:\n";
82+
buf << "expected " << expected << "\n"
83+
<< " got " << value;
84+
assumeAllAttrAndCall({ throw new MirError(buf << getData, file, line); });
85+
}
86+
else
87+
/// ditto
88+
void opEquals(scope const ubyte[] expected, string file = __FILE__, int line = __LINE__)
89+
@safe pure nothrow @nogc
90+
{
91+
import mir.format: stringBuf, getData;
92+
if (value == expected)
93+
return;
94+
auto buf = stringBuf;
95+
import mir.format: printHexArray;
96+
import mir.ndslice.topology: map;
97+
buf << "mir.test.should:\n";
98+
buf << "expected ";
99+
buf.printHexArray(expected);
100+
buf << "\n";
101+
buf << " got ";
102+
buf.printHexArray( value);
103+
assumeAllAttrAndCall({ throw new MirError(buf << getData, file, line); });
86104
}
87105
}
88106

@@ -98,6 +116,9 @@ unittest
98116
{
99117
1.0.should == 1;
100118
should(1) == 1;
119+
120+
ubyte[] val = [0, 2, 3];
121+
val.should = [0, 2, 3];
101122
}
102123

103124
///

0 commit comments

Comments
 (0)