| 1 | //! This parser and the tests are a translation of the official Python netrc library. |
| 2 | |
| 3 | use craterust-analyzer cargo rust-netrc 0.1.2 crate/::lexrust-analyzer cargo rust-netrc 0.1.2 lex/::Lexrust-analyzer cargo rust-netrc 0.1.2 lex/Lex#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#; |
| 5 | |
| 6 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 7 | pub struct ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError# { |
| 8 | linenorust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#lineno.: u32, |
| 9 | messagerust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 10 | } |
| 11 | |
| 12 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError# { |
| 13 | fn fmtrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[ParsingError][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 14 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "parsing error: {} (line {})", self.messagerust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#message., self.linenorust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#lineno.) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | /// Authenticators for host. |
| 19 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 20 | pub struct Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator# { |
| 21 | /// Identify a user on the remote machine. |
| 22 | pub loginrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#login.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 23 | |
| 24 | /// Supply an additional account password. |
| 25 | pub accountrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#account.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 26 | |
| 27 | /// Supply a password |
| 28 | pub passwordrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#password.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 29 | } |
| 30 | |
| 31 | impl Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator# { |
| 32 | #[allow(dead_code)] |
| 33 | pub fn newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().(login: &str, account: &str, password: &str) -> Selfrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator] { |
| 34 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator# { |
| 35 | loginrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#login.: login.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 36 | accountrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#account.: account.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 37 | passwordrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#password.: password.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /// Represents the netrc file. |
| 43 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 44 | pub struct Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc# { |
| 45 | /// Dictionary mapping host names to the authentificators. |
| 46 | pub hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#>, |
| 47 | |
| 48 | /// Dictionary mapping macro names to string lists. |
| 49 | pub macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#macros.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 50 | } |
| 51 | |
| 52 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc# { |
| 53 | fn fmtrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 54 | let mut rep = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 55 | for (host, attrs) in self.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() { |
| 56 | rep.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("machine {}\n\tlogin {}\n", host, attrs.loginrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#login.)); |
| 57 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().attrs.accountrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#account..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 58 | rep.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("\taccount {}\n", attrs.accountrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#account.)); |
| 59 | } |
| 60 | rep.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("\tpassword {}\n", attrs.passwordrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#password.)); |
| 61 | } |
| 62 | for (macro_, lines) in self.macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#macros..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() { |
| 63 | rep.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("macdef {}\n", macro_)); |
| 64 | for line in lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 65 | rep.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}\n", line)); |
| 66 | } |
| 67 | } |
| 68 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", rep) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc# { |
| 73 | type Errrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]Err# = ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#; |
| 74 | |
| 75 | fn from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr], ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#> { |
| 76 | let mut res = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::defaultrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][Default]default().(); |
| 77 | let mut lexer = Lexrust-analyzer cargo rust-netrc 0.1.2 lex/Lex#::newrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]new().(s); |
| 78 | |
| 79 | loop { |
| 80 | let saved_lineno = lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno.; |
| 81 | let tt = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 82 | if tt.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 83 | break; |
| 84 | } |
| 85 | if tt.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('#') { |
| 86 | if lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().saved_lineno && tt.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 87 | lexer.read_linerust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]read_line().(); |
| 88 | } |
| 89 | continue; |
| 90 | } |
| 91 | |
| 92 | #[allow(clippy::needless_late_init)] |
| 93 | let entryname; |
| 94 | match tt.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 95 | "" => { |
| 96 | break; |
| 97 | } |
| 98 | "machine" => { |
| 99 | entryname = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 100 | } |
| 101 | "default" => { |
| 102 | entryname = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("default"); |
| 103 | } |
| 104 | "macdef" => { |
| 105 | entryname = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 106 | let mut v = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 107 | loop { |
| 108 | let line = lexer.read_linerust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]read_line().(); |
| 109 | if line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 110 | break; |
| 111 | } |
| 112 | v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()); |
| 113 | } |
| 114 | res.macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#macros..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(entryname, v); |
| 115 | continue; |
| 116 | } |
| 117 | _ => { |
| 118 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError# { |
| 119 | linenorust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#lineno.: lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno., |
| 120 | messagerust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bad toplevel token '{}'", tt), |
| 121 | }); |
| 122 | } |
| 123 | }; |
| 124 | if entryname.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 125 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError# { |
| 126 | linenorust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#lineno.: lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno., |
| 127 | messagerust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("missing '{}' name", tt), |
| 128 | }); |
| 129 | } |
| 130 | |
| 131 | let mut auth = Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::defaultrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator][Default]default().(); |
| 132 | |
| 133 | loop { |
| 134 | let prev_lineno = lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno.; |
| 135 | let tt = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 136 | if tt.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') { |
| 137 | if lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().prev_lineno { |
| 138 | lexer.read_linerust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]read_line().(); |
| 139 | } |
| 140 | continue; |
| 141 | } |
| 142 | match tt.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 143 | "" | "machine" | "default" | "macdef" => { |
| 144 | res.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(entryname, auth); |
| 145 | lexer.push_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]push_token().(&tt); |
| 146 | break; |
| 147 | } |
| 148 | "login" | "user" => { |
| 149 | auth.loginrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#login. = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 150 | } |
| 151 | "account" => { |
| 152 | auth.accountrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#account. = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 153 | } |
| 154 | "password" => { |
| 155 | auth.passwordrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#password. = lexer.get_tokenrust-analyzer cargo rust-netrc 0.1.2 lex/impl#[`Lex<'a>`]get_token().(); |
| 156 | } |
| 157 | _ => { |
| 158 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParsingErrorrust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError# { |
| 159 | linenorust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#lineno.: lexer.linenorust-analyzer cargo rust-netrc 0.1.2 lex/Lex#lineno., |
| 160 | messagerust-analyzer cargo rust-netrc 0.1.2 netrc/ParsingError#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bad follower token '{}'", tt), |
| 161 | }); |
| 162 | } |
| 163 | }; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | #[cfg(test)] |
| 172 | mod testsrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/ { |
| 173 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 174 | |
| 175 | use superrust-analyzer cargo rust-netrc 0.1.2 netrc/::*; |
| 176 | |
| 177 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 178 | fn test_toplevel_non_ordered_tokensrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_toplevel_non_ordered_tokens().() { |
| 179 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().( |
| 180 | "\ |
| 181 | machine host.domain.com password pass1 login log1 account acct1 |
| 182 | default login log2 password pass2 account acct2 |
| 183 | ", |
| 184 | ) |
| 185 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 186 | |
| 187 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 188 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 189 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log1", "acct1", "pass1") |
| 190 | ); |
| 191 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 192 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."default"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 193 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log2", "acct2", "pass2") |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 198 | fn test_toplevel_tokensrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_toplevel_tokens().() { |
| 199 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().( |
| 200 | "\ |
| 201 | machine host.domain.com login log1 password pass1 account acct1 |
| 202 | default login log2 password pass2 account acct2 |
| 203 | ", |
| 204 | ) |
| 205 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 206 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 207 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 208 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log1", "acct1", "pass1") |
| 209 | ); |
| 210 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 211 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."default"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 212 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log2", "acct2", "pass2") |
| 213 | ); |
| 214 | } |
| 215 | |
| 216 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 217 | fn test_macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_macros().() { |
| 218 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().( |
| 219 | "\ |
| 220 | macdef macro1 |
| 221 | line1 |
| 222 | line2 |
| 223 | |
| 224 | macdef macro2 |
| 225 | line3 |
| 226 | line4 |
| 227 | ", |
| 228 | ) |
| 229 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 230 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nrc.macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#macros.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."macro1"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["line1", "line2"]); |
| 231 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nrc.macrosrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#macros.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."macro2"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["line3", "line4"]); |
| 232 | } |
| 233 | |
| 234 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 235 | fn test_optional_tokens_machinerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_optional_tokens_machine().() { |
| 236 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 237 | "machine host.domain.com", |
| 238 | "machine host.domain.com login", |
| 239 | "machine host.domain.com account", |
| 240 | "machine host.domain.com password", |
| 241 | "machine host.domain.com login \"\" account", |
| 242 | "machine host.domain.com login \"\" password", |
| 243 | "machine host.domain.com account \"\" password", |
| 244 | ]; |
| 245 | |
| 246 | for item in data { |
| 247 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(item).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("", "", "")); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 253 | fn test_optional_tokens_defaultrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_optional_tokens_default().() { |
| 254 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 255 | "default", |
| 256 | "default login", |
| 257 | "default account", |
| 258 | "default password", |
| 259 | "default login \"\" account", |
| 260 | "default login \"\" password", |
| 261 | "default account \"\" password", |
| 262 | ]; |
| 263 | |
| 264 | for item in data { |
| 265 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(item).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 266 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."default"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("", "", "")); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 271 | fn test_invalid_tokensrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_invalid_tokens().() { |
| 272 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 273 | ( |
| 274 | "invalid host.domain.com", |
| 275 | "parsing error: bad toplevel token 'invalid' (line 1)", |
| 276 | ), |
| 277 | ( |
| 278 | "machine host.domain.com invalid", |
| 279 | "parsing error: bad follower token 'invalid' (line 1)", |
| 280 | ), |
| 281 | ( |
| 282 | "machine host.domain.com login log password pass account acct invalid", |
| 283 | "parsing error: bad follower token 'invalid' (line 1)", |
| 284 | ), |
| 285 | ( |
| 286 | "default host.domain.com invalid", |
| 287 | "parsing error: bad follower token 'host.domain.com' (line 1)", |
| 288 | ), |
| 289 | ( |
| 290 | "default host.domain.com login log password pass account acct invalid", |
| 291 | "parsing error: bad follower token 'host.domain.com' (line 1)", |
| 292 | ), |
| 293 | ]; |
| 294 | |
| 295 | for (item, msg) in data { |
| 296 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(item); |
| 297 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nrc.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), msg); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | fn test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().(data: &str, token: &str, value: &str) { |
| 302 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 303 | match token { |
| 304 | "login" => { |
| 305 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 306 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 307 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().(value, "acct", "pass") |
| 308 | ); |
| 309 | } |
| 310 | "account" => { |
| 311 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 312 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 313 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log", value, "pass") |
| 314 | ); |
| 315 | } |
| 316 | "password" => { |
| 317 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 318 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."host.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 319 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("log", "acct", value) |
| 320 | ); |
| 321 | } |
| 322 | _ => {} |
| 323 | }; |
| 324 | } |
| 325 | |
| 326 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 327 | fn test_token_value_quotesrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_quotes().() { |
| 328 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 329 | "\ |
| 330 | machine host.domain.com login \"log\" password pass account acct |
| 331 | ", |
| 332 | "login", |
| 333 | "log", |
| 334 | ); |
| 335 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 336 | "\ |
| 337 | machine host.domain.com login log password pass account \"acct\" |
| 338 | ", |
| 339 | "account", |
| 340 | "acct", |
| 341 | ); |
| 342 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 343 | "\ |
| 344 | machine host.domain.com login log password \"pass\" account acct |
| 345 | ", |
| 346 | "password", |
| 347 | "pass", |
| 348 | ); |
| 349 | } |
| 350 | |
| 351 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 352 | fn test_token_value_escaperust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_escape().() { |
| 353 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 354 | r#"machine host.domain.com login \"log password pass account acct"#, |
| 355 | "login", |
| 356 | "\"log", |
| 357 | ); |
| 358 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 359 | "\ |
| 360 | machine host.domain.com login \"\\\"log\" password pass account acct |
| 361 | ", |
| 362 | "login", |
| 363 | "\"log", |
| 364 | ); |
| 365 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 366 | "\ |
| 367 | machine host.domain.com login log password pass account \\\"acct |
| 368 | ", |
| 369 | "account", |
| 370 | "\"acct", |
| 371 | ); |
| 372 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 373 | "\ |
| 374 | machine host.domain.com login log password pass account \"\\\"acct\" |
| 375 | ", |
| 376 | "account", |
| 377 | "\"acct", |
| 378 | ); |
| 379 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 380 | "\ |
| 381 | machine host.domain.com login log password \\\"pass account acct |
| 382 | ", |
| 383 | "password", |
| 384 | "\"pass", |
| 385 | ); |
| 386 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 387 | "\ |
| 388 | machine host.domain.com login log password \"\\\"pass\" account acct |
| 389 | ", |
| 390 | "password", |
| 391 | "\"pass", |
| 392 | ); |
| 393 | } |
| 394 | |
| 395 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 396 | fn test_token_value_whitespacerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_whitespace().() { |
| 397 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 398 | r#"machine host.domain.com login "lo g" password pass account acct"#, |
| 399 | "login", |
| 400 | "lo g", |
| 401 | ); |
| 402 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 403 | r#"machine host.domain.com login log password "pas s" account acct"#, |
| 404 | "password", |
| 405 | "pas s", |
| 406 | ); |
| 407 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 408 | r#"machine host.domain.com login log password pass account "acc t""#, |
| 409 | "account", |
| 410 | "acc t", |
| 411 | ); |
| 412 | } |
| 413 | |
| 414 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 415 | fn test_token_value_non_asciirust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_non_ascii().() { |
| 416 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 417 | r#"machine host.domain.com login ¡¢ password pass account acct"#, |
| 418 | "login", |
| 419 | "¡¢", |
| 420 | ); |
| 421 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 422 | r#"machine host.domain.com login log password pass account ¡¢"#, |
| 423 | "account", |
| 424 | "¡¢", |
| 425 | ); |
| 426 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 427 | r#"machine host.domain.com login log password ¡¢ account acct"#, |
| 428 | "password", |
| 429 | "¡¢", |
| 430 | ); |
| 431 | } |
| 432 | |
| 433 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 434 | fn test_token_value_leading_hashrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_leading_hash().() { |
| 435 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 436 | r#"machine host.domain.com login #log password pass account acct"#, |
| 437 | "login", |
| 438 | "#log", |
| 439 | ); |
| 440 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 441 | r#"machine host.domain.com login log password pass account #acct"#, |
| 442 | "account", |
| 443 | "#acct", |
| 444 | ); |
| 445 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 446 | r#"machine host.domain.com login log password #pass account acct"#, |
| 447 | "password", |
| 448 | "#pass", |
| 449 | ); |
| 450 | } |
| 451 | |
| 452 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 453 | fn test_token_value_trailing_hashrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_trailing_hash().() { |
| 454 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 455 | r#"machine host.domain.com login log# password pass account acct"#, |
| 456 | "login", |
| 457 | "log#", |
| 458 | ); |
| 459 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 460 | r#"machine host.domain.com login log password pass account acct#"#, |
| 461 | "account", |
| 462 | "acct#", |
| 463 | ); |
| 464 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 465 | r#"machine host.domain.com login log password pass# account acct"#, |
| 466 | "password", |
| 467 | "pass#", |
| 468 | ); |
| 469 | } |
| 470 | |
| 471 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 472 | fn test_token_value_internal_hashrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_value_internal_hash().() { |
| 473 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 474 | r#"machine host.domain.com login lo#g password pass account acct"#, |
| 475 | "login", |
| 476 | "lo#g", |
| 477 | ); |
| 478 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 479 | r#"machine host.domain.com login log password pass account ac#ct"#, |
| 480 | "account", |
| 481 | "ac#ct", |
| 482 | ); |
| 483 | test_token_xrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_token_x().( |
| 484 | r#"machine host.domain.com login log password pa#ss account acct"#, |
| 485 | "password", |
| 486 | "pa#ss", |
| 487 | ); |
| 488 | } |
| 489 | |
| 490 | fn test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().(data: &str) { |
| 491 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().(data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 492 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 493 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."foo.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 494 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("bar", "", "pass") |
| 495 | ); |
| 496 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 497 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."bar.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 498 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("foo", "", "pass") |
| 499 | ); |
| 500 | } |
| 501 | |
| 502 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 503 | fn test_comment_before_machine_linerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_before_machine_line().() { |
| 504 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 505 | r#"# comment |
| 506 | machine foo.domain.com login bar password pass |
| 507 | machine bar.domain.com login foo password pass |
| 508 | "#, |
| 509 | ); |
| 510 | } |
| 511 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 512 | fn test_comment_before_machine_line_no_spacerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_before_machine_line_no_space().() { |
| 513 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 514 | r#"#comment |
| 515 | machine foo.domain.com login bar password pass |
| 516 | machine bar.domain.com login foo password pass |
| 517 | "#, |
| 518 | ); |
| 519 | } |
| 520 | |
| 521 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 522 | fn test_comment_before_machine_line_hash_onlyrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_before_machine_line_hash_only().() { |
| 523 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 524 | r#"# |
| 525 | machine foo.domain.com login bar password pass |
| 526 | machine bar.domain.com login foo password pass |
| 527 | "#, |
| 528 | ); |
| 529 | } |
| 530 | |
| 531 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 532 | fn test_comment_after_machine_linerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_after_machine_line().() { |
| 533 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 534 | r#"machine foo.domain.com login bar password pass |
| 535 | # comment |
| 536 | machine bar.domain.com login foo password pass |
| 537 | "#, |
| 538 | ); |
| 539 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 540 | r#"machine foo.domain.com login bar password pass |
| 541 | machine bar.domain.com login foo password pass |
| 542 | # comment |
| 543 | "#, |
| 544 | ); |
| 545 | } |
| 546 | |
| 547 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 548 | fn test_comment_after_machine_line_no_spacerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_after_machine_line_no_space().() { |
| 549 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 550 | r#"machine foo.domain.com login bar password pass |
| 551 | #comment |
| 552 | machine bar.domain.com login foo password pass |
| 553 | "#, |
| 554 | ); |
| 555 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 556 | r#"machine foo.domain.com login bar password pass |
| 557 | machine bar.domain.com login foo password pass |
| 558 | #comment |
| 559 | "#, |
| 560 | ); |
| 561 | } |
| 562 | |
| 563 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 564 | fn test_comment_after_machine_line_hash_onlyrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_after_machine_line_hash_only().() { |
| 565 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 566 | r#"machine foo.domain.com login bar password pass |
| 567 | # |
| 568 | machine bar.domain.com login foo password pass |
| 569 | "#, |
| 570 | ); |
| 571 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 572 | r#"machine foo.domain.com login bar password pass |
| 573 | machine bar.domain.com login foo password pass |
| 574 | # |
| 575 | "#, |
| 576 | ); |
| 577 | } |
| 578 | |
| 579 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 580 | fn test_comment_at_end_of_machine_linerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_at_end_of_machine_line().() { |
| 581 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 582 | r#"machine foo.domain.com login bar password pass # comment |
| 583 | machine bar.domain.com login foo password pass |
| 584 | "#, |
| 585 | ); |
| 586 | } |
| 587 | |
| 588 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 589 | fn test_comment_at_end_of_machine_line_no_spacerust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_at_end_of_machine_line_no_space().() { |
| 590 | test_commentrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment().( |
| 591 | r#"machine foo.domain.com login bar password pass #comment |
| 592 | machine bar.domain.com login foo password pass |
| 593 | "#, |
| 594 | ); |
| 595 | } |
| 596 | |
| 597 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 598 | fn test_comment_at_end_of_machine_line_pass_has_hashrust-analyzer cargo rust-netrc 0.1.2 netrc/tests/test_comment_at_end_of_machine_line_pass_has_hash().() { |
| 599 | let nrc = Netrcrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#::from_strrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Netrc][FromStr]from_str().( |
| 600 | r#"machine foo.domain.com login bar password #pass #comment |
| 601 | machine bar.domain.com login foo password pass |
| 602 | "#, |
| 603 | ) |
| 604 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 605 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 606 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."foo.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 607 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("bar", "", "#pass") |
| 608 | ); |
| 609 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 610 | nrc.hostsrust-analyzer cargo rust-netrc 0.1.2 netrc/Netrc#hosts.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."bar.domain.com"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 611 | Authenticatorrust-analyzer cargo rust-netrc 0.1.2 netrc/Authenticator#::newrust-analyzer cargo rust-netrc 0.1.2 netrc/impl#[Authenticator]new().("foo", "", "pass") |
| 612 | ); |
| 613 | } |
| 614 | } |