github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/todolist/todolist_test.gno (about) 1 package todolist 2 3 import ( 4 "std" 5 "testing" 6 ) 7 8 func TestNewTodoList(t *testing.T) { 9 title := "My Todo List" 10 todoList := NewTodoList(title) 11 12 if todoList.GetTodolistTitle() != title { 13 t.Errorf("Expected title %q, got %q", title, todoList.GetTodolistTitle()) 14 } 15 16 if len(todoList.GetTasks()) != 0 { 17 t.Errorf("Expected 0 tasks, got %d", len(todoList.GetTasks())) 18 } 19 20 if todoList.GetTodolistOwner() != std.GetOrigCaller() { 21 t.Errorf("Expected owner %v, got %v", std.GetOrigCaller(), todoList.GetTodolistOwner()) 22 } 23 } 24 25 func TestNewTask(t *testing.T) { 26 title := "My Task" 27 task := NewTask(title) 28 29 if task.Title != title { 30 t.Errorf("Expected title %q, got %q", title, task.Title) 31 } 32 33 if task.Done { 34 t.Errorf("Expected task to be not done, but it is done") 35 } 36 } 37 38 func TestAddTask(t *testing.T) { 39 todoList := NewTodoList("My Todo List") 40 task := NewTask("My Task") 41 42 todoList.AddTask(1, task) 43 44 tasks := todoList.GetTasks() 45 if len(tasks) != 1 { 46 t.Errorf("Expected 1 task, got %d", len(tasks)) 47 } 48 49 if tasks[0] != task { 50 t.Errorf("Expected task %v, got %v", task, tasks[0]) 51 } 52 } 53 54 func TestToggleTaskStatus(t *testing.T) { 55 task := NewTask("My Task") 56 57 ToggleTaskStatus(task) 58 59 if !task.Done { 60 t.Errorf("Expected task to be done, but it is not done") 61 } 62 63 ToggleTaskStatus(task) 64 65 if task.Done { 66 t.Errorf("Expected task to be not done, but it is done") 67 } 68 } 69 70 func TestRemoveTask(t *testing.T) { 71 todoList := NewTodoList("My Todo List") 72 task := NewTask("My Task") 73 todoList.AddTask(1, task) 74 75 todoList.RemoveTask("1") 76 77 tasks := todoList.GetTasks() 78 if len(tasks) != 0 { 79 t.Errorf("Expected 0 tasks, got %d", len(tasks)) 80 } 81 }