Skip to content

Commit 460bb9f

Browse files
committed
complete Writing Automated Tests
1 parent a00bc80 commit 460bb9f

File tree

97 files changed

+1571
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1571
-158
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
tests/integration\PYGZus{}test.rs
3+
\end{Verbatim}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{c+cp}{\PYGZsh{}[cfg(test)]}
3+
\PYG{k}{mod} \PYG{n+nn}{tests}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
4+
\PYG{+w}{ }\PYG{k}{use}\PYG{+w}{ }\PYG{k}{super}::\PYG{o}{*}\PYG{p}{;}
5+
6+
\PYG{+w}{ }\PYG{c+cp}{\PYGZsh{}[test]}
7+
\PYG{+w}{ }\PYG{k}{fn} \PYG{n+nf}{larger\PYGZus{}can\PYGZus{}hold\PYGZus{}smaller}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
8+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{larger}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{Rectangle}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
9+
\PYG{+w}{ }\PYG{n}{width}: \PYG{l+m+mi}{8}\PYG{p}{,}
10+
\PYG{+w}{ }\PYG{n}{height}: \PYG{l+m+mi}{7}\PYG{p}{,}
11+
\PYG{+w}{ }\PYG{p}{\PYGZcb{};}
12+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{smaller}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{Rectangle}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
13+
\PYG{+w}{ }\PYG{n}{width}: \PYG{l+m+mi}{5}\PYG{p}{,}
14+
\PYG{+w}{ }\PYG{n}{height}: \PYG{l+m+mi}{1}\PYG{p}{,}
15+
\PYG{+w}{ }\PYG{p}{\PYGZcb{};}
16+
17+
\PYG{+w}{ }\PYG{n+nf+fm}{assert!}\PYG{p}{(}\PYG{n}{larger}\PYG{p}{.}\PYG{n}{can\PYGZus{}hold}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{smaller}\PYG{p}{));}
18+
\PYG{+w}{ }\PYG{p}{\PYGZcb{}}
19+
\PYG{p}{\PYGZcb{}}
20+
\end{Verbatim}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYGZdl{} cargo run
3+
Compiling chapter10 v0.1.0 \PYG{o}{(}file:///projects/chapter10\PYG{o}{)}
4+
error\PYG{o}{[}E0106\PYG{o}{]}: missing lifetime specifier
5+
\PYGZhy{}\PYGZhy{}\PYGZgt{} src/main.rs:9:33
6+
\PYG{p}{|}
7+
\PYG{l+m}{9} \PYG{p}{|} fn longest\PYG{o}{(}x: \PYG{p}{\PYGZam{}}str, y: \PYG{p}{\PYGZam{}}str\PYG{o}{)} \PYGZhy{}\PYGZgt{} \PYG{p}{\PYGZam{}}str \PYG{o}{\PYGZob{}}
8+
\PYG{p}{|} \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{} \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{} \PYGZca{} expected named lifetime parameter
9+
\PYG{p}{|}
10+
\PYG{o}{=} help: this \PYG{k}{function}\PYG{l+s+s1}{\PYGZsq{}s return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`}
11+
\PYG{l+s+s1}{help: consider introducing a named lifetime parameter}
12+
\PYG{l+s+s1}{ |}
13+
\PYG{l+s+s1}{9 | fn longest\PYGZlt{}\PYGZsq{}}a\PYGZgt{}\PYG{o}{(}x: \PYG{p}{\PYGZam{}}\PYG{l+s+s1}{\PYGZsq{}a str, y: \PYGZam{}\PYGZsq{}}a str\PYG{o}{)} \PYGZhy{}\PYGZgt{} \PYG{p}{\PYGZam{}}\PYG{err}{\PYGZsq{}}a str \PYG{o}{\PYGZob{}}
14+
\PYG{p}{|} ++++ ++ ++ ++
15+
16+
For more information about this error, try \PYG{l+s+sb}{`}rustc \PYGZhy{}\PYGZhy{}explain E0106\PYG{l+s+sb}{`}.
17+
error: could not compile \PYG{l+s+sb}{`}chapter10\PYG{l+s+sb}{`} due to previous error
18+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{k}{fn} \PYG{n+nf}{foo}\PYG{o}{\PYGZlt{}\PYGZsq{}}\PYG{n+na}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{n+na}{b}\PYG{o}{\PYGZgt{}}\PYG{p}{(}\PYG{n}{x}: \PYG{k+kp}{\PYGZam{}}\PYG{o}{\PYGZsq{}}\PYG{n+na}{a} \PYG{k+kt}{i32}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{y}: \PYG{k+kp}{\PYGZam{}}\PYG{o}{\PYGZsq{}}\PYG{n+na}{b} \PYG{k+kt}{i32}\PYG{p}{);}
3+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{n+nb+bp}{self}
3+
\end{Verbatim}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYGZdl{} cargo run
3+
Compiling chapter10 v0.1.0 \PYG{o}{(}file:///projects/chapter10\PYG{o}{)}
4+
error\PYG{o}{[}E0597\PYG{o}{]}: \PYG{l+s+sb}{`}string2\PYG{l+s+sb}{`} does not live long enough
5+
\PYGZhy{}\PYGZhy{}\PYGZgt{} src/main.rs:6:44
6+
\PYG{p}{|}
7+
\PYG{l+m}{6} \PYG{p}{|} \PYG{n+nv}{result} \PYG{o}{=} longest\PYG{o}{(}string1.as\PYGZus{}str\PYG{o}{()}, string2.as\PYGZus{}str\PYG{o}{())}\PYG{p}{;}
8+
\PYG{p}{|} \PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{}\PYGZca{} borrowed value does not live long enough
9+
\PYG{l+m}{7} \PYG{p}{|} \PYG{o}{\PYGZcb{}}
10+
\PYG{p}{|} \PYGZhy{} \PYG{l+s+sb}{`}string2\PYG{l+s+sb}{`} dropped here \PYG{k}{while} still borrowed
11+
\PYG{l+m}{8} \PYG{p}{|} println!\PYG{o}{(}\PYG{l+s+s2}{\PYGZdq{}The longest string is \PYGZob{}\PYGZcb{}\PYGZdq{}}, result\PYG{o}{)}\PYG{p}{;}
12+
\PYG{p}{|} \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{} borrow later used here
13+
14+
For more information about this error, try \PYG{l+s+sb}{`}rustc \PYGZhy{}\PYGZhy{}explain E0597\PYG{l+s+sb}{`}.
15+
error: could not compile \PYG{l+s+sb}{`}chapter10\PYG{l+s+sb}{`} due to previous error
16+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{n+nf+fm}{println!}
3+
\end{Verbatim}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{o}{\PYGZam{}}\PYG{k+kt}{i32}\PYG{+w}{ }\PYG{c+c1}{// a reference}
3+
\PYG{o}{\PYGZam{}\PYGZsq{}}\PYG{n+na}{a}\PYG{+w}{ }\PYG{k+kt}{i32}\PYG{+w}{ }\PYG{c+c1}{// a reference with an explicit lifetime}
4+
\PYG{o}{\PYGZam{}\PYGZsq{}}\PYG{n+na}{a}\PYG{+w}{ }\PYG{k}{mut}\PYG{+w}{ }\PYG{k+kt}{i32}\PYG{+w}{ }\PYG{c+c1}{// a mutable reference with an explicit lifetime}
5+
\end{Verbatim}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{k}{fn} \PYG{n+nf}{main}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
3+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{string1}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{String}::\PYG{n}{from}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}abcd\PYGZdq{}}\PYG{p}{);}
4+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{string2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}xyz\PYGZdq{}}\PYG{p}{;}
5+
6+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{result}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{longest}\PYG{p}{(}\PYG{n}{string1}\PYG{p}{.}\PYG{n}{as\PYGZus{}str}\PYG{p}{(),}\PYG{+w}{ }\PYG{n}{string2}\PYG{p}{);}
7+
\PYG{+w}{ }\PYG{n+nf+fm}{println!}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The longest string is \PYGZob{}\PYGZcb{}\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{result}\PYG{p}{);}
8+
\PYG{p}{\PYGZcb{}}
9+
\end{Verbatim}

0 commit comments

Comments
 (0)