Showing the changes to git-object/tests (3 of 4 files). Show all
Unified · Split
| @@ -1,137 +1,2 @@ | |||
| 1 | mod object { | 1 | mod object; |
| 2 | mod time { | 2 | mod tag; |
| 3 | use bstr::ByteSlice; | ||
| 4 | use git_object::{Sign, Time}; | ||
| 5 | |||
| 6 | #[test] | ||
| 7 | fn write_to() { | ||
| 8 | for (time, expected) in &[ | ||
| 9 | ( | ||
| 10 | Time { | ||
| 11 | time: 500, | ||
| 12 | offset: 9000, | ||
| 13 | sign: Sign::Plus, | ||
| 14 | }, | ||
| 15 | "500 +0230", | ||
| 16 | ), | ||
| 17 | ( | ||
| 18 | Time { | ||
| 19 | time: 189009009, | ||
| 20 | offset: 36000, | ||
| 21 | sign: Sign::Minus, | ||
| 22 | }, | ||
| 23 | "189009009 -1000", | ||
| 24 | ), | ||
| 25 | ( | ||
| 26 | Time { | ||
| 27 | time: 0, | ||
| 28 | offset: 0, | ||
| 29 | sign: Sign::Minus, | ||
| 30 | }, | ||
| 31 | "0 -0000", | ||
| 32 | ), | ||
| 33 | ] { | ||
| 34 | let mut output = Vec::new(); | ||
| 35 | time.write_to(&mut output).unwrap(); | ||
| 36 | assert_eq!(output.as_bstr(), expected); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | mod signature { | ||
| 42 | mod write_to { | ||
| 43 | mod invalid { | ||
| 44 | use git_object::{owned, Sign, Time}; | ||
| 45 | |||
| 46 | #[test] | ||
| 47 | fn name() { | ||
| 48 | let signature = owned::Signature { | ||
| 49 | name: "invalid < middlename".into(), | ||
| 50 | email: "ok".into(), | ||
| 51 | time: default_time(), | ||
| 52 | }; | ||
| 53 | assert_eq!( | ||
| 54 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 55 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 56 | ); | ||
| 57 | } | ||
| 58 | |||
| 59 | #[test] | ||
| 60 | fn email() { | ||
| 61 | let signature = owned::Signature { | ||
| 62 | name: "ok".into(), | ||
| 63 | email: "server>.example.com".into(), | ||
| 64 | time: default_time(), | ||
| 65 | }; | ||
| 66 | assert_eq!( | ||
| 67 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 68 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 69 | ); | ||
| 70 | } | ||
| 71 | |||
| 72 | #[test] | ||
| 73 | fn name_with_newline() { | ||
| 74 | let signature = owned::Signature { | ||
| 75 | name: "hello\nnewline".into(), | ||
| 76 | email: "name@example.com".into(), | ||
| 77 | time: default_time(), | ||
| 78 | }; | ||
| 79 | assert_eq!( | ||
| 80 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 81 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 82 | ); | ||
| 83 | } | ||
| 84 | |||
| 85 | fn default_time() -> Time { | ||
| 86 | Time { | ||
| 87 | time: 0, | ||
| 88 | offset: 0, | ||
| 89 | sign: Sign::Plus, | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | use bstr::ByteSlice; | ||
| 96 | use git_object::{borrowed, owned}; | ||
| 97 | |||
| 98 | #[test] | ||
| 99 | fn round_trip() { | ||
| 100 | for input in &[ | ||
| 101 | &b"Sebastian Thiel <byronimo@gmail.com> 1 -0030"[..], | ||
| 102 | ".. ☺️Sebastian 王知明 Thiel🙌 .. <byronimo@gmail.com> 1528473343 +0230".as_bytes(), | ||
| 103 | ".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <byronimo@gmail.com> 1528473343 +0230".as_bytes(), | ||
| 104 | ] { | ||
| 105 | let signature: owned::Signature = borrowed::Signature::from_bytes(input).unwrap().into(); | ||
| 106 | let mut output = Vec::new(); | ||
| 107 | signature.write_to(&mut output).unwrap(); | ||
| 108 | assert_eq!(output.as_bstr(), input.as_bstr()); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | mod tag { | ||
| 115 | use crate::fixture_bytes; | ||
| 116 | use bstr::ByteSlice; | ||
| 117 | use git_object::{borrowed, owned}; | ||
| 118 | |||
| 119 | // Git checks out text files with different line feeds, which causes parsing failure. | ||
| 120 | // No way to configure this in the checkout action :/ | ||
| 121 | #[cfg_attr(windows, ignore)] | ||
| 122 | #[test] | ||
| 123 | fn round_trip() { | ||
| 124 | for input in &[ | ||
| 125 | "tag/empty.txt", | ||
| 126 | "tag/whitespace.txt", | ||
| 127 | "tag/with-newlines.txt", | ||
| 128 | "tag/signed.txt", | ||
| 129 | ] { | ||
| 130 | let input = fixture_bytes(input); | ||
| 131 | let tag: owned::Tag = borrowed::Tag::from_bytes(&input).unwrap().into(); | ||
| 132 | let mut output = Vec::new(); | ||
| 133 | tag.write_to(&mut output).unwrap(); | ||
| 134 | assert_eq!(input.as_bstr(), output.as_bstr()); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| @@ -0,0 +1,110 @@ | |||
| 1 | mod time { | ||
| 2 | use bstr::ByteSlice; | ||
| 3 | use git_object::{Sign, Time}; | ||
| 4 | |||
| 5 | #[test] | ||
| 6 | fn write_to() { | ||
| 7 | for (time, expected) in &[ | ||
| 8 | ( | ||
| 9 | Time { | ||
| 10 | time: 500, | ||
| 11 | offset: 9000, | ||
| 12 | sign: Sign::Plus, | ||
| 13 | }, | ||
| 14 | "500 +0230", | ||
| 15 | ), | ||
| 16 | ( | ||
| 17 | Time { | ||
| 18 | time: 189009009, | ||
| 19 | offset: 36000, | ||
| 20 | sign: Sign::Minus, | ||
| 21 | }, | ||
| 22 | "189009009 -1000", | ||
| 23 | ), | ||
| 24 | ( | ||
| 25 | Time { | ||
| 26 | time: 0, | ||
| 27 | offset: 0, | ||
| 28 | sign: Sign::Minus, | ||
| 29 | }, | ||
| 30 | "0 -0000", | ||
| 31 | ), | ||
| 32 | ] { | ||
| 33 | let mut output = Vec::new(); | ||
| 34 | time.write_to(&mut output).unwrap(); | ||
| 35 | assert_eq!(output.as_bstr(), expected); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | mod signature { | ||
| 41 | mod write_to { | ||
| 42 | mod invalid { | ||
| 43 | use git_object::{owned, Sign, Time}; | ||
| 44 | |||
| 45 | #[test] | ||
| 46 | fn name() { | ||
| 47 | let signature = owned::Signature { | ||
| 48 | name: "invalid < middlename".into(), | ||
| 49 | email: "ok".into(), | ||
| 50 | time: default_time(), | ||
| 51 | }; | ||
| 52 | assert_eq!( | ||
| 53 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 54 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 55 | ); | ||
| 56 | } | ||
| 57 | |||
| 58 | #[test] | ||
| 59 | fn email() { | ||
| 60 | let signature = owned::Signature { | ||
| 61 | name: "ok".into(), | ||
| 62 | email: "server>.example.com".into(), | ||
| 63 | time: default_time(), | ||
| 64 | }; | ||
| 65 | assert_eq!( | ||
| 66 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 67 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 68 | ); | ||
| 69 | } | ||
| 70 | |||
| 71 | #[test] | ||
| 72 | fn name_with_newline() { | ||
| 73 | let signature = owned::Signature { | ||
| 74 | name: "hello\nnewline".into(), | ||
| 75 | email: "name@example.com".into(), | ||
| 76 | time: default_time(), | ||
| 77 | }; | ||
| 78 | assert_eq!( | ||
| 79 | format!("{:?}", signature.write_to(Vec::new())), | ||
| 80 | "Err(Custom { kind: Other, error: IllegalCharacter })" | ||
| 81 | ); | ||
| 82 | } | ||
| 83 | |||
| 84 | fn default_time() -> Time { | ||
| 85 | Time { | ||
| 86 | time: 0, | ||
| 87 | offset: 0, | ||
| 88 | sign: Sign::Plus, | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | use bstr::ByteSlice; | ||
| 95 | use git_object::{borrowed, owned}; | ||
| 96 | |||
| 97 | #[test] | ||
| 98 | fn round_trip() { | ||
| 99 | for input in &[ | ||
| 100 | &b"Sebastian Thiel <byronimo@gmail.com> 1 -0030"[..], | ||
| 101 | ".. ☺️Sebastian 王知明 Thiel🙌 .. <byronimo@gmail.com> 1528473343 +0230".as_bytes(), | ||
| 102 | ".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <byronimo@gmail.com> 1528473343 +0230".as_bytes(), | ||
| 103 | ] { | ||
| 104 | let signature: owned::Signature = borrowed::Signature::from_bytes(input).unwrap().into(); | ||
| 105 | let mut output = Vec::new(); | ||
| 106 | signature.write_to(&mut output).unwrap(); | ||
| 107 | assert_eq!(output.as_bstr(), input.as_bstr()); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | use crate::fixture_bytes; | ||
| 2 | use bstr::ByteSlice; | ||
| 3 | use git_object::{borrowed, owned}; | ||
| 4 | |||
| 5 | // Git checks out text files with different line feeds, which causes parsing failure. | ||
| 6 | // No way to configure this in the checkout action :/ | ||
| 7 | #[cfg_attr(windows, ignore)] | ||
| 8 | #[test] | ||
| 9 | fn round_trip() { | ||
| 10 | for input in &[ | ||
| 11 | "tag/empty.txt", | ||
| 12 | "tag/whitespace.txt", | ||
| 13 | "tag/with-newlines.txt", | ||
| 14 | "tag/signed.txt", | ||
| 15 | ] { | ||
| 16 | let input = fixture_bytes(input); | ||
| 17 | let tag: owned::Tag = borrowed::Tag::from_bytes(&input).unwrap().into(); | ||
| 18 | let mut output = Vec::new(); | ||
| 19 | tag.write_to(&mut output).unwrap(); | ||
| 20 | assert_eq!(input.as_bstr(), output.as_bstr()); | ||
| 21 | } | ||
| 22 | } | ||