|
| 1 | +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// xfail-fast no compile flags for check-fast |
| 12 | + |
| 13 | +// we want this to be compiled to avoid bitrot, but the actual test |
| 14 | +//has to be conducted by a human, i.e. someone (you?) compiling this |
| 15 | +//file with a plain rustc invocation and running it and checking it |
| 16 | +//works. |
| 17 | + |
| 18 | +// compile-flags: --cfg robot_mode |
| 19 | + |
| 20 | +extern mod extra; |
| 21 | +use extra::rl; |
| 22 | + |
| 23 | +static HISTORY_FILE: &'static str = "rl-human-test-history.txt"; |
| 24 | + |
| 25 | +fn main() { |
| 26 | + // don't run this in robot mode, but still typecheck it. |
| 27 | + if !cfg!(robot_mode) { |
| 28 | + println("~~ Welcome to the rl test \"suite\". ~~"); |
| 29 | + println!("Operations: |
| 30 | + - restrict the history to 2 lines, |
| 31 | + - set the tab-completion to suggest three copies of each of the last 3 letters (or 'empty'), |
| 32 | + - add 'one' and 'two' to the history, |
| 33 | + - save it to `{0}`, |
| 34 | + - add 'three', |
| 35 | + - prompt & save input (check the history & completion work and contains only 'two', 'three'), |
| 36 | + - load from `{0}` |
| 37 | + - prompt & save input (history should be 'one', 'two' again), |
| 38 | + - prompt once more. |
| 39 | +
|
| 40 | +The bool return values of each step are printed.", |
| 41 | + HISTORY_FILE); |
| 42 | + |
| 43 | + println!("restricting history length: {}", rl::set_history_max_len(3)); |
| 44 | + |
| 45 | + do rl::complete |line, suggest| { |
| 46 | + if line.is_empty() { |
| 47 | + suggest(~"empty") |
| 48 | + } else { |
| 49 | + for c in line.rev_iter().take(3) { |
| 50 | + suggest(format!("{0}{1}{1}{1}", line, c)) |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + println!("adding 'one': {}", rl::add_history("one")); |
| 56 | + println!("adding 'two': {}", rl::add_history("two")); |
| 57 | + |
| 58 | + println!("saving history: {}", rl::save_history(HISTORY_FILE)); |
| 59 | + |
| 60 | + println!("adding 'three': {}", rl::add_history("three")); |
| 61 | + |
| 62 | + match rl::read("> ") { |
| 63 | + Some(s) => println!("saving input: {}", rl::add_history(s)), |
| 64 | + None => return |
| 65 | + } |
| 66 | + println!("loading history: {}", rl::load_history(HISTORY_FILE)); |
| 67 | + |
| 68 | + match rl::read("> ") { |
| 69 | + Some(s) => println!("saving input: {}", rl::add_history(s)), |
| 70 | + None => return |
| 71 | + } |
| 72 | + |
| 73 | + rl::read("> "); |
| 74 | + } |
| 75 | +} |
0 commit comments