Debian Codegraph @

src/lossless.rs

raw symbols SCIP
1 //! A library for parsing and generating Debian patch headers.
2 //!
3 //! # Examples
4 //!
5 //! ```rust
6 //! use dep3::lossless::PatchHeader;
7 //! use std::str::FromStr;
8 //! let text = r#"From: John Doe <john.doe@example>
9 //! Date: Mon, 1 Jan 2000 00:00:00 +0000
10 //! Subject: [PATCH] fix a bug
11 //! Bug-Debian: https://bugs.debian.org/123456
12 //! Bug: https://bugzilla.example.com/bug.cgi?id=123456
13 //! Forwarded: not-needed
14 //! "#;
15 //!
16 //! let patch_header = PatchHeader::from_str(text).unwrap();
17 //! assert_eq!(patch_header.description(), Some("[PATCH] fix a bug".to_string()));
18 //! assert_eq!(patch_header.vendor_bugs("Debian").collect::<Vec<_>>(), vec!["https://bugs.debian.org/123456".to_string()]);
19 //! ```
20 use deb822_losslessrust-analyzer cargo deb822-lossless 0.5.17 crate/::Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph#;
21
22 use craterust-analyzer cargo dep3 0.2.4 crate/::fieldsrust-analyzer cargo dep3 0.2.4 fields/::*;
23
24 /// Encode free text for storage in a deb822 multi-line field value.
25 ///
26 /// deb822 multi-line values cannot contain blank lines (lines that are
27 /// empty or contain only whitespace), because the parser interprets those
28 /// as paragraph separators. By convention, a blank line is represented
29 /// as a continuation line containing only a single dot (` .`). This
30 /// function applies that encoding so that the result is safe to pass to
31 /// [`Paragraph::insert`].
32 fn encode_multiline_valuerust-analyzer cargo dep3 0.2.4 lossless/encode_multiline_value().(text: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
33 // Replace every \n followed by another \n (or by whitespace-only
34 // content up to the next \n) with the deb822 blank-line marker.
35 let mut out = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
36 for line in text.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n') {
37 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().out.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
38 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
39 }
40 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().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().out.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
41 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(" .");
42 } else {
43 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(line);
44 }
45 }
46 out
47 }
48
49 /// A Debian patch header.
50 pub struct PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#(Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph#);
51
52 impl PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader# {
53 /// Create a new, empty patch header.
54 pub fn newrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]new().() -> Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader] {
55 PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#(Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph#::newrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]new().())
56 }
57
58 /// Get a reference to the underlying `Paragraph`.
59 pub fn as_deb822rust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]as_deb822().(&self) -> &Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph# {
60 &self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
61 }
62
63 /// Get a mutable reference to the underlying `Paragraph`, mutably.
64 pub fn as_deb822_mutrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]as_deb822_mut().(&mut self) -> &mut Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph# {
65 &mut self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
66 }
67
68 /// The origin of the patch.
69 pub fn originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]origin().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OriginCategoryrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#>, Originrust-analyzer cargo dep3 0.2.4 fields/Origin#)> {
70 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
71 .getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Origin")
72 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
73 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(craterust-analyzer cargo dep3 0.2.4 crate/::fieldsrust-analyzer cargo dep3 0.2.4 fields/::parse_originrust-analyzer cargo dep3 0.2.4 fields/parse_origin().)
74 }
75
76 /// Set the origin of the patch.
77 pub fn set_originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_origin().(&mut self, category: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OriginCategoryrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#>, origin: Originrust-analyzer cargo dep3 0.2.4 fields/Origin#) {
78 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().(
79 "Origin",
80 craterust-analyzer cargo dep3 0.2.4 crate/::fieldsrust-analyzer cargo dep3 0.2.4 fields/::format_originrust-analyzer cargo dep3 0.2.4 fields/format_origin().(&category, &origin).as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(),
81 );
82 }
83
84 /// The `Forwarded` field.
85 pub fn forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]forwarded().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Forwardedrust-analyzer cargo dep3 0.2.4 fields/Forwarded#> {
86 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
87 .getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Forwarded")
88 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
89 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
90 }
91
92 /// Set the `Forwarded` field.
93 pub fn set_forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_forwarded().(&mut self, forwarded: Forwardedrust-analyzer cargo dep3 0.2.4 fields/Forwarded#) {
94 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Forwarded", forwarded.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
95 }
96
97 /// The author of the patch.
98 pub fn authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
99 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Author").or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("From"))
100 }
101
102 /// Set the author of the patch.
103 pub fn set_authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_author().(&mut self, author: &str) {
104 if self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..contains_keyrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]contains_key().("From") {
105 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("From", author);
106 } else {
107 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Author", author);
108 }
109 }
110
111 /// The `Reviewed-By` field.
112 pub fn reviewed_byrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]reviewed_by().(&self) -> 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#> {
113 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..get_allrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get_all().("Reviewed-By").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
114 }
115
116 /// Get the last update date of the patch.
117 pub fn last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#> {
118 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
119 .getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Last-Update")
120 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
121 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::parse_from_strrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]parse_from_str().(s, "%Y-%m-%d").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().())
122 }
123
124 /// Set the date of the last update
125 pub fn set_last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_last_update().(&mut self, date: chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#) {
126 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
127 .insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Last-Update", date.formatrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]format().("%Y-%m-%d").to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
128 }
129
130 /// The `Applied-Upstream` field.
131 pub fn applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]applied_upstream().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<AppliedUpstreamrust-analyzer cargo dep3 0.2.4 fields/AppliedUpstream#> {
132 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
133 .getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Applied-Upstream")
134 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
135 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
136 }
137
138 /// Set the `Applied-Upstream` field.
139 pub fn set_applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_applied_upstream().(&mut self, applied_upstream: AppliedUpstreamrust-analyzer cargo dep3 0.2.4 fields/AppliedUpstream#) {
140 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0.
141 .insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Applied-Upstream", applied_upstream.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
142 }
143
144 /// Get the bugs associated with the patch.
145 pub fn bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> + '_ {
146 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..itemsrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]items().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, v)| {
147 if k.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("Bug-") {
148 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(k.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("Bug-").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), v))
149 } else if k rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."Bug" {
150 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, v))
151 } else {
152 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
153 }
154 })
155 }
156
157 /// Get the bugs associated with a specific vendor.
158 pub fn vendor_bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]vendor_bugs().<'a>(&'a self, vendor: &'a str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> + 'a {
159 self.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, v)| {
160 if k 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#(vendor.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) {
161 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v)
162 } else {
163 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
164 }
165 })
166 }
167
168 /// Iterate over Debian BTS bug numbers parsed from `Bug-Debian:` (and a
169 /// bare `Bug:` field when no vendor is specified).
170 ///
171 /// Accepts three value forms: a bare decimal number (`123456`), a
172 /// `#`-prefixed number, or a `https://bugs.debian.org/NNNNNN` URL. Values
173 /// that don't match are silently skipped.
174 pub fn debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = u32> + '_ {
175 self.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(vendor, value)| {
176 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = vendor {
177 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().v.eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().("debian") {
178 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
179 }
180 }
181 craterust-analyzer cargo dep3 0.2.4 crate/::fieldsrust-analyzer cargo dep3 0.2.4 fields/::parse_debian_bug_idrust-analyzer cargo dep3 0.2.4 fields/parse_debian_bug_id().(&value)
182 })
183 }
184
185 /// Set the upstream bug associated with the patch.
186 pub fn set_upstream_bugrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_upstream_bug().(&mut self, bug: &str) {
187 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Bug", bug);
188 }
189
190 /// Set the bug associated with a specific vendor.
191 pub fn set_vendor_bugrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_vendor_bug().(&mut self, vendor: &str, bug: &str) {
192 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Bug-{}", vendor).as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(), bug);
193 }
194
195 /// Get the description or subject field.
196 fn description_fieldrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description_field().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
197 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Description").or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Subject"))
198 }
199
200 /// Get the description of the patch.
201 pub fn descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
202 self.description_fieldrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description_field().()
203 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
204 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(s).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
205 }
206
207 /// Set the description of the patch.
208 pub fn set_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_description().(&mut self, description: &str) {
209 let description = encode_multiline_valuerust-analyzer cargo dep3 0.2.4 lossless/encode_multiline_value().(description);
210 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subject) = self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Subject") {
211 // Replace the first line with ours
212 let new = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
213 "{}\n{}",
214 description,
215 subject.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\n').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.1).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("")
216 );
217 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..setrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]set().("Subject", new.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
218 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing) = self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Description") {
219 // Replace the first line with ours
220 let new = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
221 "{}\n{}",
222 description,
223 existing.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\n').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.1).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("")
224 );
225 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..setrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]set().("Description", new.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
226 } else {
227 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Description", description.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
228 }
229 }
230
231 /// Get the long description of the patch.
232 pub fn long_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]long_description().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
233 self.description_fieldrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description_field().()
234 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
235 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\n').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.1).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("").to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
236 }
237
238 /// Set the long description of the patch.
239 pub fn set_long_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_long_description().(&mut self, long_description: &str) {
240 let long_description = encode_multiline_valuerust-analyzer cargo dep3 0.2.4 lossless/encode_multiline_value().(long_description);
241 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subject) = self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Subject") {
242 // Keep the first line, but replace the rest with our text
243 let first_line = subject
244 .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\n')
245 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.0)
246 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(subject.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
247 let new = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}\n{}", first_line, long_description);
248 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..setrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]set().("Subject", new.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
249 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(description) = self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..getrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]get().("Description") {
250 // Keep the first line, but replace the rest with our text
251 let first_line = description
252 .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\n')
253 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.0)
254 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(description.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
255 let new = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}\n{}", first_line, long_description);
256 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..setrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]set().("Description", new.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
257 } else {
258 self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..insertrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph]insert().("Description", long_description.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
259 }
260 }
261
262 /// Write the patch header
263 pub fn writerust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]write().<W: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&self, writer: &mut W) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
264 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().())
265 }
266 }
267
268 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 PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader# {
269 fn fmtrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][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# {
270 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.0rust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#0..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
271 }
272 }
273
274 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader# {
275 fn defaultrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][Default]default().() -> Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][Default] {
276 Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][Default]::newrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]new().()
277 }
278 }
279
280 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 PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader# {
281 type Errrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]Err# = deb822_losslessrust-analyzer cargo deb822-lossless 0.5.17 crate/::ParseErrorrust-analyzer cargo deb822-lossless 0.5.17 lossless/ParseError#;
282
283 fn from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr], Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
284 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#(Paragraphrust-analyzer cargo deb822-lossless 0.5.17 lossless/Paragraph#::from_strrust-analyzer cargo deb822-lossless 0.5.17 lossless/impl#[Paragraph][FromStr]from_str().(s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().))
285 }
286 }
287
288 pub use craterust-analyzer cargo dep3 0.2.4 crate/::header_endrust-analyzer cargo dep3 0.2.4 header_end().;
289
290 impl PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader# {
291 /// Parse a patch file's DEP-3 header, tolerating a trailing unified
292 /// diff body. Splits `content` at the first `---` / `diff ` /
293 /// `Index:` line and parses only the header portion.
294 ///
295 /// Returns the parsed header and the byte offset where the diff
296 /// body starts (equal to `content.len()` if there is no diff body).
297 /// Use this for files like `debian/patches/foo.patch` where the
298 /// caller has the whole file in hand and wants just the header.
299 ///
300 /// `from_str` parses the input as deb822 in its entirety and will
301 /// fail (or, with malformed continuations, misparse) when handed a
302 /// patch with diff content; `parse_relaxed` is the appropriate
303 /// entry point for that case.
304 pub fn parse_relaxedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]parse_relaxed().(content: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Selfrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader], usize), deb822_losslessrust-analyzer cargo deb822-lossless 0.5.17 crate/::ParseErrorrust-analyzer cargo deb822-lossless 0.5.17 lossless/ParseError#> {
305 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#;
306 let end = header_endrust-analyzer cargo dep3 0.2.4 header_end().(content);
307 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(&content[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
308 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((header, end))
309 }
310 }
311
312 #[cfg(test)]
313 mod testsrust-analyzer cargo dep3 0.2.4 lossless/tests/ {
314 use superrust-analyzer cargo dep3 0.2.4 lossless/::PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#;
315 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
316 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#;
317
318 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
319 fn test_upstreamrust-analyzer cargo dep3 0.2.4 lossless/tests/test_upstream().() {
320 let text = r#"From: Ulrich Drepper <[email protected]>
321 Subject: Fix regex problems with some multi-bytes characters
322 .
323 * posix/bug-regex17.c: Add testcases.
324 * posix/regcomp.c (re_compile_fastmap_iter): Rewrite COMPLEX_BRACKET
325 handling.
326 .
327 Origin: upstream, http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bdb56bac
328 Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=9697
329 Bug-Debian: http://bugs.debian.org/510219
330 "#;
331
332 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
333
334 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
335 header.originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]origin().(),
336 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
337 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::OriginCategoryrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#::Upstreamrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#Upstream#),
338 superrust-analyzer cargo dep3 0.2.4 lossless/::Originrust-analyzer cargo dep3 0.2.4 fields/Origin#::Otherrust-analyzer cargo dep3 0.2.4 fields/Origin#Other#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
339 "http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bdb56bac"
340 ))
341 ))
342 );
343 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]forwarded().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
344 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
345 header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(),
346 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Ulrich Drepper <[email protected]>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
347 );
348 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.reviewed_byrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]reviewed_by().(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<&str>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
349 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
350 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]applied_upstream().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
351 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
352 header.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
353 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
354 (
355 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
356 "http://sourceware.org/bugzilla/show_bug.cgi?id=9697".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
357 ),
358 (
359 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Debian".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
360 "http://bugs.debian.org/510219".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
361 ),
362 ]
363 );
364 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
365 header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(),
366 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Fix regex problems with some multi-bytes characters".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
367 );
368 }
369
370 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
371 fn test_forwardedrust-analyzer cargo dep3 0.2.4 lossless/tests/test_forwarded().() {
372 let text = r#"Description: Use FHS compliant paths by default
373 Upstream is not interested in switching to those paths.
374 .
375 But we will continue using them in Debian nevertheless to comply with
376 our policy.
377 Forwarded: http://lists.example.com/oct-2006/1234.html
378 Author: John Doe <[email protected]>
379 Last-Update: 2006-12-21
380 "#;
381 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
382
383 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]origin().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
384 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
385 header.forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]forwarded().(),
386 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::Forwardedrust-analyzer cargo dep3 0.2.4 fields/Forwarded#::Yesrust-analyzer cargo dep3 0.2.4 fields/Forwarded#Yes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
387 "http://lists.example.com/oct-2006/1234.html"
388 )))
389 );
390 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
391 header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(),
392 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("John Doe <[email protected]>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
393 );
394 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.reviewed_byrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]reviewed_by().(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<&str>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
395 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
396 header.last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(),
397 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]from_ymd_opt().(2006, 12, 21).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
398 );
399 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]applied_upstream().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
400 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
401 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
402 header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(),
403 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Use FHS compliant paths by default".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
404 );
405 }
406
407 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
408 fn test_not_forwardedrust-analyzer cargo dep3 0.2.4 lossless/tests/test_not_forwarded().() {
409 let text = r#"Description: Workaround for broken symbol resolving on mips/mipsel
410 The correct fix will be done in etch and it will require toolchain
411 fixes.
412 Forwarded: not-needed
413 Origin: vendor, http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=80;bug=265678
414 Bug-Debian: http://bugs.debian.org/265678
415 Author: Thiemo Seufer <[email protected]>
416 "#;
417
418 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
419
420 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
421 header.originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]origin().(),
422 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
423 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::OriginCategoryrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#::Vendorrust-analyzer cargo dep3 0.2.4 fields/OriginCategory#Vendor#),
424 superrust-analyzer cargo dep3 0.2.4 lossless/::Originrust-analyzer cargo dep3 0.2.4 fields/Origin#::Otherrust-analyzer cargo dep3 0.2.4 fields/Origin#Other#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
425 "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=80;bug=265678"
426 ))
427 ))
428 );
429 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]forwarded().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::Forwardedrust-analyzer cargo dep3 0.2.4 fields/Forwarded#::NotNeededrust-analyzer cargo dep3 0.2.4 fields/Forwarded#NotNeeded#));
430 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
431 header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(),
432 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Thiemo Seufer <[email protected]>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
433 );
434 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.reviewed_byrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]reviewed_by().(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<&str>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
435 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
436 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]applied_upstream().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
437 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
438 header.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
439 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(
440 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Debian".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
441 "http://bugs.debian.org/265678".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
442 ),]
443 );
444
445 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
446 header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(),
447 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Workaround for broken symbol resolving on mips/mipsel".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
448 );
449 }
450
451 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
452 fn test_applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/tests/test_applied_upstream().() {
453 let text = r#"Description: Fix widget frobnication speeds
454 Frobnicating widgets too quickly tended to cause explosions.
455 Forwarded: http://lists.example.com/2010/03/1234.html
456 Author: John Doe <[email protected]>
457 Applied-Upstream: 1.2, http://bzr.example.com/frobnicator/trunk/revision/123
458 Last-Update: 2010-03-29
459 "#;
460 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
461
462 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.originrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]origin().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
463 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
464 header.forwardedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]forwarded().(),
465 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::Forwardedrust-analyzer cargo dep3 0.2.4 fields/Forwarded#::Yesrust-analyzer cargo dep3 0.2.4 fields/Forwarded#Yes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
466 "http://lists.example.com/2010/03/1234.html"
467 )))
468 );
469 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
470 header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(),
471 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("John Doe <[email protected]>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
472 );
473 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.reviewed_byrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]reviewed_by().(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<&str>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
474 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
475 header.last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(),
476 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]from_ymd_opt().(2010, 3, 29).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
477 );
478 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
479 header.applied_upstreamrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]applied_upstream().(),
480 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo dep3 0.2.4 lossless/::AppliedUpstreamrust-analyzer cargo dep3 0.2.4 fields/AppliedUpstream#::Otherrust-analyzer cargo dep3 0.2.4 fields/AppliedUpstream#Other#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
481 "1.2, http://bzr.example.com/frobnicator/trunk/revision/123"
482 )))
483 );
484 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]bugs().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
485 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
486 header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(),
487 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Fix widget frobnication speeds".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
488 );
489 }
490
491 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
492 fn test_vendor_bugsrust-analyzer cargo dep3 0.2.4 lossless/tests/test_vendor_bugs().() {
493 let text = r#"Description: Fix widget frobnication speeds
494 Bug: http://bugs.example.com/123
495 Bug-Debian: http://bugs.debian.org/123
496 Bug-Ubuntu: http://bugs.launchpad.net/123
497 "#;
498
499 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
500
501 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
502 header.vendor_bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]vendor_bugs().("Debian").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
503 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://bugs.debian.org/123".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]
504 );
505 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
506 header.vendor_bugsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]vendor_bugs().("Ubuntu").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
507 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["http://bugs.launchpad.net/123".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]
508 );
509 }
510
511 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
512 fn parse_relaxed_splits_at_dashesrust-analyzer cargo dep3 0.2.4 lossless/tests/parse_relaxed_splits_at_dashes().() {
513 let text = "Author: alice\nDescription: bla\n---\n@@ -1 +1 @@\n-x\n+y\n";
514 let (header, end) = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::parse_relaxedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]parse_relaxed().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
515 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(end, "Author: alice\nDescription: bla\n".lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
516 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("alice".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
517 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("bla".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
518 }
519
520 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
521 fn parse_relaxed_splits_at_diff_wordrust-analyzer cargo dep3 0.2.4 lossless/tests/parse_relaxed_splits_at_diff_word().() {
522 let text = "Author: alice\ndiff --git a/foo b/foo\n";
523 let (header, end) = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::parse_relaxedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]parse_relaxed().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
524 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(end, "Author: alice\n".lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
525 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("alice".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
526 }
527
528 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
529 fn parse_relaxed_splits_at_index_markerrust-analyzer cargo dep3 0.2.4 lossless/tests/parse_relaxed_splits_at_index_marker().() {
530 let text = "Author: alice\nIndex: foo\n@@ -1 +1 @@\n";
531 let (header, end) = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::parse_relaxedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]parse_relaxed().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
532 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(end, "Author: alice\n".lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
533 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("alice".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
534 }
535
536 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
537 fn parse_relaxed_handles_header_onlyrust-analyzer cargo dep3 0.2.4 lossless/tests/parse_relaxed_handles_header_only().() {
538 let text = "Author: alice\nDescription: bla\n";
539 let (header, end) = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::parse_relaxedrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]parse_relaxed().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
540 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(end, text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
541 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.authorrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]author().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("alice".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
542 }
543
544 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
545 fn header_end_handles_emptyrust-analyzer cargo dep3 0.2.4 lossless/tests/header_end_handles_empty().() {
546 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(superrust-analyzer cargo dep3 0.2.4 lossless/::header_endrust-analyzer cargo dep3 0.2.4 header_end().(""), 0);
547 }
548
549 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
550 fn test_set_last_updaterust-analyzer cargo dep3 0.2.4 lossless/tests/test_set_last_update().() {
551 let text = r#"Description: Fix widget frobnication speeds
552 "#;
553 let mut header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
554 let date = chronorust-analyzer cargo chrono 0.4.45 crate/::NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]from_ymd_opt().(2023, 5, 15).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
555 header.set_last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_last_update().(date);
556 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.last_updaterust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]last_update().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(date));
557 }
558
559 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
560 fn test_set_description_with_blank_linesrust-analyzer cargo dep3 0.2.4 lossless/tests/test_set_description_with_blank_lines().() {
561 // Descriptions containing blank lines (e.g. from fixer result messages)
562 // must be encoded as " ." continuation lines so that deb822-lossless
563 // does not reject them as empty continuation lines.
564 let mut header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::newrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]new().();
565 header.set_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_description().("Fix frobnication\n\nDetails follow.");
566 // The stored Description value must be parseable (no panic / error).
567 let rendered = header.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
568 let reparsed = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(&rendered).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
569 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reparsed.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Fix frobnication".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
570 // Blank line must have been encoded as " ."
571 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
572 rendered.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(" ."),
573 "blank line should be encoded as ' .'"
574 );
575 }
576
577 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
578 fn test_set_description_replaces_first_linerust-analyzer cargo dep3 0.2.4 lossless/tests/test_set_description_replaces_first_line().() {
579 // When a Description already exists, set_description replaces its
580 // first line while preserving the rest.
581 let text = "Description: old summary\n old long description\n";
582 let mut header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
583 header.set_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]set_description().("new summary");
584 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]description().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("new summary".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
585 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
586 header.long_descriptionrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]long_description().(),
587 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("old long description".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
588 );
589 }
590
591 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
592 fn test_debian_bug_ids_from_urlrust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_from_url().() {
593 let text = "Bug-Debian: https://bugs.debian.org/510219\n";
594 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
595 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![510219]);
596 }
597
598 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
599 fn test_debian_bug_ids_bare_bug_field_includedrust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_bare_bug_field_included().() {
600 // A bare `Bug:` field with no vendor counts as Debian per the doc.
601 let text = "Bug: 12345\n";
602 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
603 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![12345]);
604 }
605
606 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
607 fn test_debian_bug_ids_vendor_case_insensitiverust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_vendor_case_insensitive().() {
608 // Bug-DEBIAN should match too.
609 let text = "Bug-DEBIAN: #42\n";
610 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
611 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![42]);
612 }
613
614 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
615 fn test_debian_bug_ids_skips_other_vendorsrust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_skips_other_vendors().() {
616 // Non-Debian vendor bugs (and unparseable Debian values) are skipped.
617 let text = "Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=9697\n\
618 Bug-Debian: https://bugs.debian.org/510219\n\
619 Bug-Ubuntu: https://bugs.launchpad.net/bugs/12345\n";
620 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
621 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![510219]);
622 }
623
624 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
625 fn test_debian_bug_ids_multiple_entriesrust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_multiple_entries().() {
626 let text = "Bug-Debian: https://bugs.debian.org/100\n\
627 Bug-Debian: #200\n\
628 Bug-Debian: 300\n";
629 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
630 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
631 header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
632 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![100, 200, 300]
633 );
634 }
635
636 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
637 fn test_debian_bug_ids_empty_when_no_bug_fieldsrust-analyzer cargo dep3 0.2.4 lossless/tests/test_debian_bug_ids_empty_when_no_bug_fields().() {
638 let text = "Description: nothing to see here\n";
639 let header = PatchHeaderrust-analyzer cargo dep3 0.2.4 lossless/PatchHeader#::from_strrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader][FromStr]from_str().(text).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
640 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
641 header.debian_bug_idsrust-analyzer cargo dep3 0.2.4 lossless/impl#[PatchHeader]debian_bug_ids().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
642 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u32>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()
643 );
644 }
645 }