2018-06-12 19:32:55 +00:00
|
|
|
/*
|
2019-08-31 09:02:05 +00:00
|
|
|
* Copyright 2016 - 2019 Andreas Nordal
|
2018-06-12 19:32:55 +00:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::situation::Situation;
|
|
|
|
use crate::situation::Transition;
|
|
|
|
use crate::situation::WhatNow;
|
|
|
|
use crate::situation::flush;
|
2018-06-12 19:32:55 +00:00
|
|
|
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::commonstrcmd::CommonStrCmdResult;
|
|
|
|
use crate::commonstrcmd::common_str_cmd;
|
2018-06-12 19:32:55 +00:00
|
|
|
|
|
|
|
pub struct SitStrDq {}
|
|
|
|
|
|
|
|
impl Situation for SitStrDq {
|
2019-08-31 09:02:05 +00:00
|
|
|
fn whatnow(&mut self, horizon: &[u8], is_horizon_lengthenable: bool) -> WhatNow {
|
2019-06-16 15:28:45 +00:00
|
|
|
for (i, &a) in horizon.iter().enumerate() {
|
|
|
|
if a == b'\"' {
|
2019-08-31 09:02:05 +00:00
|
|
|
return WhatNow{tri: Transition::Pop, pre: i, len: 1, alt: None};
|
2018-06-12 19:32:55 +00:00
|
|
|
}
|
|
|
|
match common_str_cmd(&horizon, i, is_horizon_lengthenable, false) {
|
2020-02-23 17:51:01 +00:00
|
|
|
CommonStrCmdResult::None => {}
|
2019-08-31 09:02:05 +00:00
|
|
|
CommonStrCmdResult::Some(x) |
|
2020-02-23 17:51:01 +00:00
|
|
|
CommonStrCmdResult::OnlyWithQuotes(x) => { return x; }
|
2018-06-12 19:32:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-31 09:02:05 +00:00
|
|
|
flush(horizon.len())
|
2018-06-12 19:32:55 +00:00
|
|
|
}
|
2020-02-23 19:39:27 +00:00
|
|
|
fn get_color(&self) -> u32 {
|
2019-06-10 20:11:54 +00:00
|
|
|
0x00_ff0000
|
2018-06-12 19:32:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-03 12:58:32 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::testhelpers::*;
|
2019-08-03 12:58:32 +00:00
|
|
|
#[cfg(test)]
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::sitcmd::SitNormal;
|
2019-08-03 12:58:32 +00:00
|
|
|
#[cfg(test)]
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::sitvec::SitVec;
|
2019-08-03 12:58:32 +00:00
|
|
|
#[cfg(test)]
|
2020-02-22 20:57:57 +00:00
|
|
|
use crate::situation::COLOR_MAGIC;
|
2019-08-03 12:58:32 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sit_strdq() {
|
2019-08-31 09:02:05 +00:00
|
|
|
let found_cmdsub = WhatNow{
|
2019-08-03 12:58:32 +00:00
|
|
|
tri: Transition::Push(Box::new(SitNormal{
|
|
|
|
end_trigger: u16::from(b')'), end_replace: None,
|
|
|
|
})), pre: 0, len: 2, alt: None
|
2019-08-31 09:02:05 +00:00
|
|
|
};
|
|
|
|
let found_math = WhatNow{
|
2019-08-03 12:58:32 +00:00
|
|
|
tri: Transition::Push(Box::new(SitVec{
|
|
|
|
terminator: vec!{b')', b')'},
|
|
|
|
color: COLOR_MAGIC,
|
|
|
|
})), pre: 0, len: 3, alt: None
|
2019-08-31 09:02:05 +00:00
|
|
|
};
|
|
|
|
sit_expect!(SitStrDq{}, b"", &flush(0));
|
|
|
|
sit_expect!(SitStrDq{}, b"$", &flush(0), &flush(1));
|
|
|
|
sit_expect!(SitStrDq{}, b"$(", &flush(0), &found_cmdsub);
|
2019-08-03 12:58:32 +00:00
|
|
|
sit_expect!(SitStrDq{}, b"$( ", &found_cmdsub);
|
|
|
|
sit_expect!(SitStrDq{}, b"$((", &found_math);
|
|
|
|
}
|