| 1 | module util |
| 2 | |
| 3 | fn test_new_suggestion_preallocates_the_bounded_storage() { |
| 4 | s := new_suggestion('missing_name', []string{}, SuggestionParams{}) |
| 5 | assert s.known.len == 0 |
| 6 | assert s.known.cap == max_suggestions_limit |
| 7 | } |
| 8 | |
| 9 | fn test_new_suggestion_caps_the_number_of_known_possibilities() { |
| 10 | mut possibilities := []string{cap: int(max_suggestions_limit) + 50} |
| 11 | for i in 0 .. int(max_suggestions_limit) + 50 { |
| 12 | possibilities << 'candidate_${i}' |
| 13 | } |
| 14 | s := new_suggestion('missing_name', possibilities, SuggestionParams{}) |
| 15 | assert s.known.len == max_suggestions_limit |
| 16 | assert s.known.cap == max_suggestions_limit |
| 17 | known_values := s.known.map(it.value) |
| 18 | assert 'candidate_0' in known_values |
| 19 | assert 'candidate_${max_suggestions_limit - 1}' in known_values |
| 20 | assert 'candidate_${max_suggestions_limit}' !in known_values |
| 21 | } |
| 22 | |