-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.tex
50 lines (40 loc) · 1.14 KB
/
example.tex
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
\documentclass{article}
\usepackage{xcolor}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\usepackage{listings, listings-zig}
\lstdefinestyle{customCodeStyle}{
backgroundcolor=\color{backcolour},
frame=single,
columns=spaceflexible
}
\lstset{
style=customCodeStyle,
numbers=left,
numberstyle=\small
}
\title{Zig Lstlisting Example}
\author{Brook Jeynes}
\begin{document}
\maketitle
\begin{lstlisting}[language=Zig, caption=Example from https://ziglang.org/]
const std = @import("std");
const parseInt = std.fmt.parseInt;
test "parse integers" {
const input = "123 67 89,99";
const ally = std.testing.allocator;
var list = std.ArrayList(u32).init(ally);
// Ensure the list is freed at scope exit.
// Try commenting out this line!
defer list.deinit();
var it = std.mem.tokenize(u8, input, " ,");
while (it.next()) |num| {
const n = try parseInt(u32, num, 10);
try list.append(n);
}
const expected = [_]u32{ 123, 67, 89, 99 };
for (expected, list.items) |exp, actual| {
try std.testing.expectEqual(exp, actual);
}
}
\end{lstlisting}
\end{document}