mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-22 19:21:27 +01:00
test(cursor): initial test
Implementation has to follow next
This commit is contained in:
@@ -8,11 +8,32 @@ use std::io;
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
||||
use std::string::ToString;
|
||||
use std::io::{Write, Read, stdout};
|
||||
|
||||
use std::default::Default;
|
||||
|
||||
const FIELD_SEP: &'static str = ".";
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct FieldCursor(Vec<String>);
|
||||
|
||||
impl ToString for FieldCursor {
|
||||
fn to_string(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl FieldCursor {
|
||||
pub fn set(&mut self, value: &str) -> Result<(), CLIError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn num_fields(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError)
|
||||
-> (&'a str, Option<&'a str>) {
|
||||
let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string()));
|
||||
|
||||
@@ -151,4 +151,44 @@ bar\r\n\
|
||||
assert_eq!(r.0.first, 2);
|
||||
assert_eq!(r.0.last, 42);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_cli {
|
||||
use super::cli::cmn::*;
|
||||
|
||||
use std::default::Default;
|
||||
|
||||
#[test]
|
||||
fn cursor() {
|
||||
let mut c: FieldCursor = Default::default();
|
||||
|
||||
assert_eq!(c.to_string(), "");
|
||||
assert_eq!(c.num_fields(), 0);
|
||||
assert!(c.set(".").is_ok());
|
||||
assert!(c.set("..").is_err());
|
||||
assert_eq!(c.num_fields(), 0);
|
||||
|
||||
assert!(c.set("foo").is_ok());
|
||||
assert_eq!(c.to_string(), "foo");
|
||||
assert_eq!(c.num_fields(), 1);
|
||||
assert!(c.set("..").is_ok());
|
||||
assert_eq!(c.num_fields(), 0);
|
||||
assert_eq!(c.to_string(), "");
|
||||
|
||||
assert!(c.set("foo.").is_err());
|
||||
|
||||
assert!(c.set("foo.bar").is_ok());
|
||||
assert_eq!(c.num_fields(), 2);
|
||||
assert_eq!(c.to_string(), "foo.bar");
|
||||
assert!(c.set("sub.level").is_ok());
|
||||
assert_eq!(c.num_fields(), 4);
|
||||
assert_eq!(c.to_string(), "foo.bar.sub.level");
|
||||
assert!(c.set("...other").is_ok());
|
||||
assert_eq!(c.to_string(), "foo.bar.other");
|
||||
assert_eq!(c.num_fields(), 3);
|
||||
assert!(c.set(".one.two.three...beer").is_ok());
|
||||
assert_eq!(c.num_fields(), 2);
|
||||
assert_eq!(c.to_string(), "one.beer");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user