@@ -233,3 +233,85 @@ fn lang_filter(args: Vec<Object>) -> Object {
233233fn lang_sort ( args : Vec < Object > ) -> Object {
234234 Object :: Error ( String :: from ( "TODO: sort is not implemented yet" ) )
235235}
236+
237+ #[ test]
238+ fn test_lang_len_buildin ( ) {
239+ let input = vec ! [ Object :: Array ( vec![ Object :: Int ( 2 ) , Object :: Int ( 2 ) ] ) ] ;
240+ match lang_len ( input) {
241+ Object :: Int ( i) => assert_eq ! ( i, 2 ) ,
242+ o => panic ! ( "lang_len did return {} instead of Int" , o) ,
243+ } ;
244+ }
245+
246+ #[ test]
247+ fn test_lang_first_buildin_normal_array ( ) {
248+ let input = vec ! [ Object :: Array ( vec![
249+ Object :: Int ( 1 ) ,
250+ Object :: Int ( 2 ) ,
251+ Object :: Int ( 3 ) ,
252+ ] ) ] ;
253+
254+ match lang_first ( input) {
255+ Object :: Int ( i) => assert_eq ! ( i, 1 ) ,
256+ o => panic ! ( "Expected Int got {} instead" , o) ,
257+ } ;
258+ }
259+
260+ #[ test]
261+ fn test_lang_first_buildin_empty_array ( ) {
262+ let input = vec ! [ Object :: Array ( Vec :: new( ) ) ] ;
263+
264+ match lang_first ( input) {
265+ Object :: Null => ( ) ,
266+ o => panic ! ( "Expected Null from the empty list. Got {} instead" , o) ,
267+ } ;
268+ }
269+
270+ #[ test]
271+ fn test_lang_last_buildin_normal_array ( ) {
272+ let input = vec ! [ Object :: Array ( vec![
273+ Object :: Int ( 1 ) ,
274+ Object :: Int ( 2 ) ,
275+ Object :: Int ( 3 ) ,
276+ ] ) ] ;
277+
278+ match lang_last ( input) {
279+ Object :: Int ( i) => assert_eq ! ( i, 3 ) ,
280+ o => panic ! ( "Expected Int got {} instead" , o) ,
281+ } ;
282+ }
283+
284+ #[ test]
285+ fn test_lang_last_buildin_empty_array ( ) {
286+ let input = vec ! [ Object :: Array ( Vec :: new( ) ) ] ;
287+
288+ match lang_last ( input) {
289+ Object :: Null => ( ) ,
290+ o => panic ! ( "Expected Null from the empty list. Got {} instead" , o) ,
291+ } ;
292+ }
293+
294+ #[ test]
295+ fn test_lang_tail_buildin_normal_array ( ) {
296+ let input = vec ! [ Object :: Array ( vec![
297+ Object :: Int ( 1 ) ,
298+ Object :: Int ( 2 ) ,
299+ Object :: Int ( 3 ) ,
300+ ] ) ] ;
301+
302+ let input_tail = Object :: Array ( vec ! [ Object :: Int ( 2 ) , Object :: Int ( 3 ) ] ) ;
303+
304+ match lang_tail ( input) {
305+ o => assert_eq ! ( input_tail, o) ,
306+ } ;
307+ }
308+
309+ #[ test]
310+ fn test_lang_tail_buildin_empty_array ( ) {
311+ let input = vec ! [ Object :: Array ( Vec :: new( ) ) ] ;
312+
313+ match lang_last ( input) {
314+ Object :: Null => ( ) ,
315+ o => panic ! ( "Expected Null from the empty list. Got {} instead" , o) ,
316+ } ;
317+ }
0 commit comments