• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TyRoXx / NonlocalityOS / 14426917358

13 Apr 2025 06:26AM UTC coverage: 77.858% (+0.3%) from 77.554%
14426917358

Pull #221

github

web-flow
Merge 68ad2d613 into 57594d285
Pull Request #221: Hello world

134 of 137 new or added lines in 2 files covered. (97.81%)

1 existing line in 1 file now uncovered.

4195 of 5388 relevant lines covered (77.86%)

1749.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/lambda/src/hello_world_tests.rs
1
use crate::{
2
    builtins::{BUILTINS_NAMESPACE, LAMBDA_APPLY_METHOD_NAME},
3
    expressions::{evaluate, Expression, LambdaExpression, Pointer, ReadVariable},
4
    types::{Interface, Name, NamespaceId, Signature, Type, TypedExpression},
5
};
6
use astraea::{
7
    storage::{store_object, InMemoryValueStorage, StoreValue},
8
    tree::{BlobDigest, HashedValue, Value, ValueBlob},
9
};
10
use std::{collections::BTreeMap, pin::Pin, sync::Arc};
11

12
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
13
struct ConsoleOutput {
14
    pub message: BlobDigest,
15
}
16

17
impl ConsoleOutput {
18
    pub fn to_value(&self) -> Value {
1✔
19
        Value::new(ValueBlob::empty(), vec![self.message])
1✔
20
    }
21

22
    pub fn from_value(value: &Value) -> Option<ConsoleOutput> {
1✔
23
        if value.blob().len() != 0 {
1✔
UNCOV
24
            return None;
×
25
        }
26
        if value.references().len() != 1 {
1✔
NEW
27
            return None;
×
28
        }
29
        Some(ConsoleOutput {
1✔
30
            message: value.references()[0],
1✔
31
        })
32
    }
33
}
34

35
#[tokio::test]
36
async fn hello_world() {
2✔
37
    let storage = Arc::new(InMemoryValueStorage::empty());
2✔
38
    let namespace = NamespaceId([42; 16]);
2✔
39
    let console_output_name = Name::new(namespace, "ConsoleOutput".to_string());
2✔
40
    let console_output_type = Type::Named(console_output_name);
2✔
41
    let hello_world_string = Arc::new(Value::from_string("Hello, world!\n").unwrap());
2✔
42
    let hello_world_string_ref = storage
3✔
43
        .store_value(&HashedValue::from(hello_world_string))
2✔
44
        .await
2✔
45
        .unwrap();
46
    let console_output = ConsoleOutput {
47
        message: hello_world_string_ref,
48
    };
49
    let console_output_value = Arc::new(console_output.to_value());
2✔
50
    let console_output_expression = TypedExpression::new(
51
        Expression::Literal(
2✔
52
            console_output_type.clone(),
2✔
53
            HashedValue::from(console_output_value.clone()),
2✔
54
        ),
55
        console_output_type.clone(),
2✔
56
    );
57
    let lambda_parameter_name = Name::new(namespace, "unused_arg".to_string());
2✔
58
    let lambda_expression = TypedExpression::new(
59
        Expression::Lambda(Box::new(LambdaExpression::new(
2✔
60
            console_output_type.clone(),
2✔
61
            lambda_parameter_name.clone(),
2✔
62
            console_output_expression.expression,
2✔
63
        ))),
64
        Type::Function(Box::new(Signature::new(
2✔
65
            console_output_type.clone(),
2✔
66
            console_output_type.clone(),
2✔
67
        ))),
68
    );
69
    {
70
        let mut program_as_string = String::new();
2✔
71
        lambda_expression
2✔
72
            .expression
2✔
73
            .print(&mut program_as_string, 0)
2✔
74
            .unwrap();
75
        assert_eq!("(unused_arg) =>\n  literal(ConsoleOutput, 09e593654f7d4be82ed8ef897a98f0c23c45d5b49ec58a5c8e9df679bf204e0bd2d7b184002cf1348726dfc5ae6d25a5ce57b36177839f474388486aa27f5ece)", program_as_string.as_str());
76
    }
77
    let read_variable: Arc<ReadVariable> = Arc::new(
78
        move |_name: &Name| -> Pin<Box<dyn core::future::Future<Output = Pointer> + Send>> {
2✔
79
            todo!()
1✔
80
        },
81
    );
82
    let read_literal = {
2✔
83
        let console_output_type = console_output_type.clone();
2✔
84
        move |literal_type: Type,
1✔
85
              value: HashedValue|
1✔
86
              -> Pin<Box<dyn core::future::Future<Output = Pointer> + Send>> {
2✔
87
            assert_eq!(console_output_type, literal_type);
88
            Box::pin(async move { Pointer::Value(value) })
4✔
89
        }
90
    };
91
    let main_function = evaluate(
92
        &lambda_expression.expression,
2✔
93
        &*storage,
2✔
94
        &read_variable,
2✔
95
        &read_literal,
2✔
96
    )
97
    .await;
2✔
98
    let apply_name = Name::new(BUILTINS_NAMESPACE, LAMBDA_APPLY_METHOD_NAME.to_string());
2✔
99
    let lambda_interface = Arc::new(Interface::new(BTreeMap::from([(
2✔
100
        apply_name.clone(),
2✔
101
        Signature::new(Type::Unit, console_output_type.clone()),
2✔
102
    )])));
103
    let lambda_interface_ref = store_object(&*storage, &*lambda_interface).await.unwrap();
4✔
104
    let result = main_function
3✔
105
        .call_method(
106
            &lambda_interface_ref,
2✔
107
            &apply_name,
2✔
108
            &Pointer::Value(HashedValue::from(Arc::new(Value::empty()))),
2✔
109
            &*storage,
2✔
110
            &read_variable,
2✔
111
            &read_literal,
2✔
112
        )
113
        .await
2✔
114
        .unwrap();
115
    let serialized_result = match result {
3✔
116
        Pointer::Value(value) => value,
2✔
117
        _ => panic!("Expected a Value"),
118
    };
119
    let deserialized_result = ConsoleOutput::from_value(serialized_result.value()).unwrap();
2✔
120
    assert_eq!(&console_output, &deserialized_result);
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc