feat: EvalState.new_value_int
(cherry picked from commit aa79e4d0db7795ab059349e6f6bc764d17afe003)
This commit is contained in:
parent
cd5fa278eb
commit
024ef333cb
1 changed files with 25 additions and 0 deletions
|
|
@ -137,6 +137,16 @@ impl EvalState {
|
|||
Ok(v)
|
||||
}
|
||||
|
||||
pub fn new_value_int(&self, i: Int) -> Result<Value> {
|
||||
let v = unsafe {
|
||||
let value = self.new_value_uninitialized();
|
||||
raw::init_int(self.context.ptr(), value.raw_ptr(), i);
|
||||
value
|
||||
};
|
||||
self.context.check_err()?;
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
/// Not exposed, because the caller must always explicitly handle the context or not accept one at all.
|
||||
fn get_string(&self, value: &Value) -> Result<String> {
|
||||
let mut r = result_string_init!();
|
||||
|
|
@ -495,6 +505,21 @@ mod tests {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_state_new_int() {
|
||||
gc_registering_current_thread(|| {
|
||||
let store = Store::open("auto").unwrap();
|
||||
let es = EvalState::new(store).unwrap();
|
||||
let v = es.new_value_int(42).unwrap();
|
||||
es.force(&v).unwrap();
|
||||
let t = es.value_type(&v).unwrap();
|
||||
assert!(t == ValueType::Int);
|
||||
let i = es.require_int(&v).unwrap();
|
||||
assert!(i == 42);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_state_value_attrset() {
|
||||
gc_registering_current_thread(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue