1use std::collections::BTreeMap;
47use std::fmt::Write as _;
48
49use base64::Engine as _;
50use hpr_motor::text::Parsed;
51use hpr_motor::{MotorError, ThrustCurve, eng, rse};
52use serde::{Deserialize, Serialize};
53
54use crate::motor_finder::{self, MANUFACTURERS};
55use crate::{Client, Fetched, NetError, Source, Transport};
56
57pub const BASE_URL: &str = "https://www.thrustcurve.org/api/v1";
59
60pub const TTL_S: u64 = 86_400;
62
63pub const MAX_RESULTS: u32 = 5_000;
67
68pub const ATTRIBUTION: &str = "Motor data and thrust curves courtesy of ThrustCurve.org, \
70 https://www.thrustcurve.org/";
71
72#[non_exhaustive]
75#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
76pub struct Search {
77 pub manufacturer: Option<String>,
79 pub designation: Option<String>,
81 pub common_name: Option<String>,
83 pub impulse_class: Option<String>,
85 pub max_results: Option<u32>,
87}
88
89impl Search {
90 #[must_use]
92 pub fn manufacturer(name: &str) -> Self {
93 Self {
94 manufacturer: Some(name.to_owned()),
95 max_results: Some(MAX_RESULTS),
96 ..Self::default()
97 }
98 }
99
100 #[must_use]
103 pub fn url(&self) -> String {
104 let max_results = self.max_results.map(|n| n.to_string());
105 let fields = [
106 ("manufacturer", self.manufacturer.as_deref()),
107 ("designation", self.designation.as_deref()),
108 ("commonName", self.common_name.as_deref()),
109 ("impulseClass", self.impulse_class.as_deref()),
110 ("maxResults", max_results.as_deref()),
111 ];
112 let query: Vec<String> = fields
113 .iter()
114 .filter_map(|(name, value)| Some(format!("{name}={}", encode(value.as_ref()?))))
115 .collect();
116 if query.is_empty() {
117 return format!("{BASE_URL}/search.json");
118 }
119 format!("{BASE_URL}/search.json?{}", query.join("&"))
120 }
121}
122
123#[non_exhaustive]
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
126pub enum Format {
127 #[serde(rename = "RASP")]
129 Rasp,
130 #[serde(rename = "RockSim")]
132 RockSim,
133}
134
135impl Format {
136 #[must_use]
138 pub fn as_str(self) -> &'static str {
139 match self {
140 Self::Rasp => "RASP",
141 Self::RockSim => "RockSim",
142 }
143 }
144}
145
146#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
149pub struct Download {
150 motor_id: String,
151 format: Format,
152}
153
154impl Download {
155 pub fn new(motor_id: &str, format: Format) -> Result<Self, ThrustCurveError> {
162 if !is_motor_id(motor_id) {
163 return Err(ThrustCurveError::Request {
164 what: "motor id",
165 value: motor_id.to_owned(),
166 });
167 }
168 Ok(Self {
169 motor_id: motor_id.to_ascii_lowercase(),
170 format,
171 })
172 }
173
174 #[must_use]
176 pub fn motor_id(&self) -> &str {
177 &self.motor_id
178 }
179
180 #[must_use]
182 pub fn format(&self) -> Format {
183 self.format
184 }
185
186 #[must_use]
188 pub fn url(&self) -> String {
189 format!(
190 "{BASE_URL}/download.json?motorId={}&format={}&data=file",
191 self.motor_id,
192 self.format.as_str()
193 )
194 }
195}
196
197#[must_use]
200pub fn source() -> Source {
201 Source {
202 name: "ThrustCurve.org".to_owned(),
203 attribution: ATTRIBUTION.to_owned(),
204 ttl_s: TTL_S,
205 }
206}
207
208#[non_exhaustive]
210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
211pub struct SearchAnswer {
212 pub criteria: Vec<Criterion>,
214 pub matches: u32,
217 pub results: Vec<MotorRecord>,
219 #[serde(skip_serializing_if = "Option::is_none")]
221 pub source_url: Option<String>,
222}
223
224impl SearchAnswer {
225 #[must_use]
227 pub fn is_complete(&self) -> bool {
228 usize::try_from(self.matches).ok() == Some(self.results.len())
229 }
230}
231
232#[non_exhaustive]
234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
235pub struct Criterion {
236 pub name: String,
238 pub value: String,
240 pub matches: u32,
242}
243
244#[non_exhaustive]
248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
249#[serde(rename_all = "camelCase")]
250pub struct MotorRecord {
251 pub motor_id: String,
253 pub manufacturer: String,
255 #[serde(skip_serializing_if = "Option::is_none")]
257 pub manufacturer_abbrev: Option<String>,
258 pub designation: String,
260 #[serde(skip_serializing_if = "Option::is_none")]
262 pub common_name: Option<String>,
263 #[serde(skip_serializing_if = "Option::is_none")]
265 pub impulse_class: Option<String>,
266 #[serde(skip_serializing_if = "Option::is_none")]
268 pub cert_org: Option<String>,
269 #[serde(rename = "diameter", skip_serializing_if = "Option::is_none")]
271 pub diameter_mm: Option<f64>,
272 #[serde(rename = "length", skip_serializing_if = "Option::is_none")]
274 pub length_mm: Option<f64>,
275 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
277 pub motor_type: Option<String>,
278 #[serde(rename = "avgThrustN", skip_serializing_if = "Option::is_none")]
280 pub avg_thrust_n: Option<f64>,
281 #[serde(rename = "maxThrustN", skip_serializing_if = "Option::is_none")]
283 pub max_thrust_n: Option<f64>,
284 #[serde(rename = "totImpulseNs", skip_serializing_if = "Option::is_none")]
286 pub total_impulse_ns: Option<f64>,
287 #[serde(rename = "burnTimeS", skip_serializing_if = "Option::is_none")]
289 pub burn_time_s: Option<f64>,
290 #[serde(skip_serializing_if = "Option::is_none")]
292 pub data_files: Option<u32>,
293 #[serde(skip_serializing_if = "Option::is_none")]
295 pub info_url: Option<String>,
296 #[serde(rename = "totalWeightG", skip_serializing_if = "Option::is_none")]
298 pub total_weight_g: Option<f64>,
299 #[serde(rename = "propWeightG", skip_serializing_if = "Option::is_none")]
301 pub propellant_weight_g: Option<f64>,
302 #[serde(skip_serializing_if = "Option::is_none")]
304 pub delays: Option<String>,
305 #[serde(skip_serializing_if = "Option::is_none")]
307 pub delay_adjustable: Option<bool>,
308 #[serde(skip_serializing_if = "Option::is_none")]
310 pub case_info: Option<String>,
311 #[serde(skip_serializing_if = "Option::is_none")]
313 pub prop_info: Option<String>,
314 #[serde(skip_serializing_if = "Option::is_none")]
316 pub sparky: Option<bool>,
317 #[serde(skip_serializing_if = "Option::is_none")]
319 pub updated_on: Option<String>,
320 #[serde(skip_serializing_if = "Option::is_none")]
322 pub availability: Option<String>,
323 #[serde(rename = "source_url", skip_serializing_if = "Option::is_none")]
325 pub source_url: Option<String>,
326}
327
328#[non_exhaustive]
330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
331pub struct DownloadAnswer {
332 pub results: Vec<DataFile>,
334}
335
336#[non_exhaustive]
338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
339#[serde(rename_all = "camelCase")]
340pub struct DataFile {
341 pub motor_id: String,
343 pub simfile_id: String,
345 pub format: Format,
347 #[serde(skip_serializing_if = "Option::is_none")]
350 pub source: Option<String>,
351 #[serde(skip_serializing_if = "Option::is_none")]
354 pub license: Option<String>,
355 pub data: String,
357 #[serde(skip_serializing_if = "Option::is_none")]
359 pub info_url: Option<String>,
360 #[serde(skip_serializing_if = "Option::is_none")]
362 pub data_url: Option<String>,
363 #[serde(rename = "source_url", skip_serializing_if = "Option::is_none")]
365 pub source_url: Option<String>,
366}
367
368#[non_exhaustive]
370#[derive(Debug, Clone, PartialEq)]
371pub enum Curve {
372 Rasp(Parsed<eng::EngFile>),
374 RockSim(Parsed<rse::RseFile>),
376}
377
378impl Curve {
379 pub fn thrust_curve(&self) -> Result<ThrustCurve, MotorError> {
384 let none = || MotorError::Inconsistent("the file holds no motor".to_owned());
385 match self {
386 Self::Rasp(parsed) => parsed
387 .value
388 .entries
389 .first()
390 .ok_or_else(none)?
391 .thrust_curve(),
392 Self::RockSim(parsed) => parsed
393 .value
394 .engines
395 .first()
396 .ok_or_else(none)?
397 .thrust_curve(),
398 }
399 }
400}
401
402impl Curve {
403 #[must_use]
406 pub fn propellant_mass_kg(&self) -> Option<f64> {
407 match self {
408 Self::Rasp(parsed) => parsed
409 .value
410 .entries
411 .first()
412 .map(|entry| entry.propellant_mass_kg),
413 Self::RockSim(parsed) => parsed
414 .value
415 .engines
416 .first()
417 .map(|engine| engine.propellant_mass_g / 1000.0),
418 }
419 }
420}
421
422impl DataFile {
423 pub fn text(&self) -> Result<String, ThrustCurveError> {
430 let bytes = base64::engine::general_purpose::STANDARD
431 .decode(&self.data)
432 .map_err(|e| field(format!("{}.data", self.simfile_id), e))?;
433 String::from_utf8(bytes)
434 .map_err(|e| field(format!("{}.data", self.simfile_id), e.utf8_error()))
435 }
436
437 pub fn read(&self) -> Result<Curve, ThrustCurveError> {
442 let text = self.text()?;
443 Ok(match self.format {
444 Format::Rasp => Curve::Rasp(eng::parse(&text)?),
445 Format::RockSim => Curve::RockSim(rse::parse(&text)?),
446 })
447 }
448}
449
450pub fn parse_search(body: &[u8]) -> Result<SearchAnswer, ThrustCurveError> {
459 #[derive(Deserialize)]
460 struct Errors {
461 error: Option<String>,
462 #[serde(default)]
463 criteria: Vec<CriterionError>,
464 }
465 #[derive(Deserialize)]
466 struct CriterionError {
467 name: String,
468 error: Option<String>,
469 }
470 let errors: Errors = json(body)?;
471 if let Some(error) = errors.error {
472 return Err(ThrustCurveError::Api(error));
473 }
474 if let Some(c) = errors.criteria.into_iter().find(|c| c.error.is_some()) {
475 let error = c.error.unwrap_or_default();
476 return Err(ThrustCurveError::Api(format!("{}: {error}", c.name)));
477 }
478 let answer: SearchAnswer = json(body)?;
479 let found = answer.results.len();
480 if usize::try_from(answer.matches).map_or(true, |m| found > m) {
481 return Err(ThrustCurveError::Count {
482 matches: answer.matches,
483 found,
484 });
485 }
486 for (i, motor) in answer.results.iter().enumerate() {
487 check_record(motor, &format!("results[{i}]"))?;
488 }
489 Ok(answer)
490}
491
492pub fn parse_download(body: &[u8]) -> Result<DownloadAnswer, ThrustCurveError> {
500 #[derive(Deserialize)]
501 struct Errors {
502 error: Option<String>,
503 }
504 if let Some(error) = json::<Errors>(body)?.error {
505 return Err(ThrustCurveError::Api(error));
506 }
507 let answer: DownloadAnswer = json(body)?;
508 for (i, file) in answer.results.iter().enumerate() {
509 if !is_motor_id(&file.motor_id) {
510 return Err(field(format!("results[{i}].motorId"), &file.motor_id));
511 }
512 base64::engine::general_purpose::STANDARD
513 .decode(&file.data)
514 .map_err(|e| field(format!("results[{i}].data"), e))?;
515 }
516 Ok(answer)
517}
518
519pub fn fetch_search<T: Transport>(
530 client: &Client<T>,
531 search: &Search,
532 now_s: u64,
533) -> Result<(SearchAnswer, Fetched), ThrustCurveError> {
534 fetch(client, &search.url(), now_s, parse_search)
535}
536
537pub fn fetch_whole_search<T: Transport>(
545 client: &Client<T>,
546 search: &Search,
547 now_s: u64,
548) -> Result<(SearchAnswer, Fetched), ThrustCurveError> {
549 let read = |body: &[u8]| {
550 let answer = parse_search(body)?;
551 if !answer.is_complete() {
552 return Err(ThrustCurveError::Incomplete {
553 matches: answer.matches,
554 found: answer.results.len(),
555 });
556 }
557 Ok(answer)
558 };
559 fetch(client, &search.url(), now_s, read)
560}
561
562pub fn fetch_download<T: Transport>(
569 client: &Client<T>,
570 download: &Download,
571 now_s: u64,
572) -> Result<(DownloadAnswer, Fetched), ThrustCurveError> {
573 let read = |body: &[u8]| {
574 let answer = parse_download(body)?;
575 let other = answer.results.iter().find(|f| {
576 !f.motor_id.eq_ignore_ascii_case(&download.motor_id) || f.format != download.format
577 });
578 if let Some(file) = other {
579 return Err(ThrustCurveError::OtherMotor {
580 asked: format!("{} ({})", download.motor_id, download.format.as_str()),
581 found: format!("{} ({})", file.motor_id, file.format.as_str()),
582 });
583 }
584 Ok(answer)
585 };
586 fetch(client, &download.url(), now_s, read)
587}
588
589pub fn fetch_finder_records<T: Transport>(
598 client: &Client<T>,
599 now_s: u64,
600) -> Result<(Vec<MotorRecord>, Vec<Fetched>), ThrustCurveError> {
601 let mut records = Vec::new();
602 let mut fetched = Vec::new();
603 for &(name, _) in MANUFACTURERS {
604 let read = |body: &[u8]| {
605 let answer = parse_search(body)?;
606 if !answer.is_complete() {
607 return Err(ThrustCurveError::Incomplete {
608 matches: answer.matches,
609 found: answer.results.len(),
610 });
611 }
612 if let Some(other) = answer.results.iter().find(|r| r.manufacturer != name) {
613 return Err(ThrustCurveError::OtherManufacturer {
614 asked: name.to_owned(),
615 found: other.manufacturer.clone(),
616 });
617 }
618 Ok(answer)
619 };
620 let (answer, f) = fetch(client, &Search::manufacturer(name).url(), now_s, read)?;
621 records.extend(answer.results);
622 fetched.push(f);
623 }
624 Ok((records, fetched))
625}
626
627#[non_exhaustive]
629#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
630pub struct Join {
631 pub mapped: Vec<Mapped>,
633 pub misses: Vec<Miss>,
635}
636
637#[non_exhaustive]
639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
640pub struct Mapped {
641 pub manufacturer: String,
643 pub designation: String,
645 pub finder_index: usize,
647 pub record: MotorRecord,
649}
650
651#[non_exhaustive]
653#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
654pub struct Miss {
655 pub manufacturer: String,
657 pub designation: String,
659 pub reason: MissReason,
661}
662
663#[non_exhaustive]
665#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
666pub enum MissReason {
667 NoRecord,
669 SeveralRecords(Vec<String>),
671}
672
673impl Join {
674 #[must_use]
676 pub fn coverage(&self) -> (usize, usize) {
677 (self.mapped.len(), self.mapped.len() + self.misses.len())
678 }
679
680 #[must_use]
684 pub fn report(&self) -> String {
685 let mut by_maker: BTreeMap<&str, (usize, usize, usize)> = BTreeMap::new();
686 for m in &self.mapped {
687 let row = by_maker.entry(&m.manufacturer).or_default();
688 row.0 += 1;
689 row.1 += 1;
690 if m.record.data_files.unwrap_or(0) == 0 {
691 row.2 += 1;
692 }
693 }
694 for m in &self.misses {
695 by_maker.entry(&m.manufacturer).or_default().1 += 1;
696 }
697 let (mapped, total) = self.coverage();
698 let mut out = String::new();
699 let _ = writeln!(
701 out,
702 "{mapped} of {total} motors mapped to one record each.\n"
703 );
704 let _ = writeln!(
705 out,
706 "| Manufacturer | Motors | Mapped | Mapped, no data file listed | Missed |"
707 );
708 let _ = writeln!(out, "|---|---:|---:|---:|---:|");
709 for (maker, (mapped, total, no_file)) in &by_maker {
710 let missed = total - mapped;
711 let _ = writeln!(
712 out,
713 "| {maker} | {total} | {mapped} | {no_file} | {missed} |"
714 );
715 }
716 let _ = writeln!(out);
717 if self.misses.is_empty() {
718 let _ = writeln!(out, "No misses.");
719 } else {
720 let _ = writeln!(out, "| Manufacturer | Designation | Why |");
721 let _ = writeln!(out, "|---|---|---|");
722 for m in &self.misses {
723 let why = match &m.reason {
724 MissReason::NoRecord => "no record of that name".to_owned(),
725 MissReason::SeveralRecords(ids) => {
726 format!("{} records of that name: {}", ids.len(), ids.join(", "))
727 }
728 };
729 let _ = writeln!(out, "| {} | `{}` | {why} |", m.manufacturer, m.designation);
730 }
731 }
732 out
733 }
734}
735
736#[must_use]
741pub fn join(motors: &[motor_finder::Motor], records: &[MotorRecord]) -> Join {
742 let mut by_name: BTreeMap<(&str, &str), Vec<&MotorRecord>> = BTreeMap::new();
743 for r in records {
744 let same_name = by_name
745 .entry((&r.manufacturer, &r.designation))
746 .or_default();
747 if same_name
748 .iter()
749 .all(|kept| !kept.motor_id.eq_ignore_ascii_case(&r.motor_id))
750 {
751 same_name.push(r);
752 }
753 }
754 let mut join = Join {
755 mapped: Vec::new(),
756 misses: Vec::new(),
757 };
758 for (finder_index, m) in motors.iter().enumerate() {
759 let found = by_name
760 .get(&(m.manufacturer.as_str(), m.designation.as_str()))
761 .map_or(&[][..], Vec::as_slice);
762 let miss = |reason| Miss {
763 manufacturer: m.manufacturer.clone(),
764 designation: m.designation.clone(),
765 reason,
766 };
767 match found {
768 [record] => join.mapped.push(Mapped {
769 manufacturer: m.manufacturer.clone(),
770 designation: m.designation.clone(),
771 finder_index,
772 record: (*record).clone(),
773 }),
774 [] => join.misses.push(miss(MissReason::NoRecord)),
775 several => join.misses.push(miss(MissReason::SeveralRecords(
776 several.iter().map(|r| r.motor_id.clone()).collect(),
777 ))),
778 }
779 }
780 join
781}
782
783fn fetch<T: Transport, R>(
785 client: &Client<T>,
786 url: &str,
787 now_s: u64,
788 read: impl Fn(&[u8]) -> Result<R, ThrustCurveError>,
789) -> Result<(R, Fetched), ThrustCurveError> {
790 let check = |body: &[u8]| read(body).map(drop).map_err(|e| e.to_string());
791 let fetched = client.fetch_checked(&source(), url, now_s, check)?;
792 let value = read(&fetched.body)?;
793 Ok((value, fetched))
794}
795
796fn is_motor_id(id: &str) -> bool {
798 id.len() == 24 && id.bytes().all(|b| b.is_ascii_hexdigit())
799}
800
801fn encode(value: &str) -> String {
804 let mut out = String::with_capacity(value.len());
805 for b in value.bytes() {
806 if b.is_ascii_alphanumeric() || b"-._~".contains(&b) {
807 out.push(char::from(b));
808 } else {
809 let _ = write!(out, "%{b:02X}");
810 }
811 }
812 out
813}
814
815fn check_record(motor: &MotorRecord, at: &str) -> Result<(), ThrustCurveError> {
817 if !is_motor_id(&motor.motor_id) {
818 return Err(field(format!("{at}.motorId"), &motor.motor_id));
819 }
820 let figures = [
821 ("diameter", motor.diameter_mm),
822 ("length", motor.length_mm),
823 ("avgThrustN", motor.avg_thrust_n),
824 ("maxThrustN", motor.max_thrust_n),
825 ("totImpulseNs", motor.total_impulse_ns),
826 ("burnTimeS", motor.burn_time_s),
827 ("totalWeightG", motor.total_weight_g),
828 ("propWeightG", motor.propellant_weight_g),
829 ];
830 for (name, value) in figures {
831 if let Some(value) = value.filter(|v| *v < 0.0) {
832 return Err(field(format!("{at}.{name}"), value));
833 }
834 }
835 Ok(())
836}
837
838fn json<'a, D: Deserialize<'a>>(body: &'a [u8]) -> Result<D, ThrustCurveError> {
840 serde_json::from_slice(body).map_err(|e| ThrustCurveError::Json(e.to_string()))
841}
842
843fn field(field: String, value: impl ToString) -> ThrustCurveError {
845 ThrustCurveError::Field {
846 field,
847 value: value.to_string(),
848 }
849}
850
851#[non_exhaustive]
853#[derive(Debug, thiserror::Error)]
854pub enum ThrustCurveError {
855 #[error("the ThrustCurve request's {what} is not one it serves: {value:?}")]
857 Request {
858 what: &'static str,
860 value: String,
862 },
863 #[error(transparent)]
865 Net(#[from] NetError),
866 #[error("the ThrustCurve answer is not of the expected shape: {0}")]
868 Json(String),
869 #[error("ThrustCurve refused the request: {0}")]
871 Api(String),
872 #[error("the ThrustCurve search says {matches} motors match but returns {found}")]
874 Count {
875 matches: u32,
877 found: usize,
879 },
880 #[error("the ThrustCurve search matches {matches} motors but returns only {found}")]
882 Incomplete {
883 matches: u32,
885 found: usize,
887 },
888 #[error("the ThrustCurve answer's {field} is not usable: {value}")]
890 Field {
891 field: String,
893 value: String,
895 },
896 #[error("asked ThrustCurve for {asked}'s motors, but the answer holds one of {found}'s")]
898 OtherManufacturer {
899 asked: String,
901 found: String,
903 },
904 #[error("asked ThrustCurve for {asked}'s files, but the answer holds {found}'s")]
906 OtherMotor {
907 asked: String,
909 found: String,
911 },
912 #[error(transparent)]
914 Motor(#[from] MotorError),
915}
916
917#[cfg(test)]
918mod tests {
919 use super::*;
920
921 #[test]
922 fn urls_follow_the_apis_names() {
923 assert_eq!(
924 Search::manufacturer("Cesaroni Technology").url(),
925 "https://www.thrustcurve.org/api/v1/search.json?manufacturer=Cesaroni%20Technology&maxResults=5000"
926 );
927 let search = Search {
928 designation: Some("F27R/L".to_owned()),
929 impulse_class: Some("F".to_owned()),
930 ..Search::default()
931 };
932 assert_eq!(
933 search.url(),
934 "https://www.thrustcurve.org/api/v1/search.json?designation=F27R%2FL&impulseClass=F"
935 );
936 assert_eq!(
937 Search::default().url(),
938 "https://www.thrustcurve.org/api/v1/search.json"
939 );
940 let download = Download::new("5f4294d2000231000000044f", Format::Rasp).unwrap();
941 assert_eq!(
942 download.url(),
943 "https://www.thrustcurve.org/api/v1/download.json?motorId=5f4294d2000231000000044f&format=RASP&data=file"
944 );
945 }
946
947 #[test]
948 fn a_motor_id_must_be_24_hex_digits() {
949 for bad in [
950 "",
951 "5f4294d2000231000000044",
952 "5f4294d2000231000000044f0",
953 "5f4294d2000231000000044g",
954 "5f4294d200023100000004&f",
955 ] {
956 let err = Download::new(bad, Format::Rasp).unwrap_err();
957 assert!(
958 matches!(&err, ThrustCurveError::Request { what: "motor id", value } if value == bad),
959 "{bad}: {err}"
960 );
961 }
962 let upper = Download::new("5F4294D2000231000000044F", Format::RockSim).unwrap();
963 assert_eq!(upper.motor_id(), "5f4294d2000231000000044f");
964 assert!(upper.url().contains("motorId=5f4294d2000231000000044f&"));
965 }
966
967 #[test]
968 fn query_values_are_percent_encoded() {
969 assert_eq!(encode("AZaz09-._~"), "AZaz09-._~");
970 assert_eq!(encode("a b/c&d=e?é"), "a%20b%2Fc%26d%3De%3F%C3%A9");
971 }
972}