2 * Copyright 2000-2017 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.stats.completion
19 import com.intellij.stats.completion.events.LogEvent
20 import com.intellij.stats.validation.InputSessionValidator
21 import com.intellij.stats.validation.SimpleSessionValidationResult
22 import org.assertj.core.api.Assertions.assertThat
25 private fun List<LogEvent>.serialize(): List<String> = map { LogEventSerializer.toString(it) }
28 class EventStreamValidatorTest {
31 fun `simple sequence of actions`() {
32 val list = listOf(LogEventFixtures.completion_started_3_items_shown, LogEventFixtures.explicit_select_position_0)
33 validate(list, list.map { LogEventSerializer.toString(it) }, emptyList())
37 fun `sample error sequence of actions`() {
38 val list = listOf(LogEventFixtures.completion_started_3_items_shown, LogEventFixtures.explicit_select_position_1)
39 validate(list, expectedOut = emptyList(), expectedErr = list.serialize())
43 fun `up down actions`() {
45 LogEventFixtures.completion_started_3_items_shown,
46 LogEventFixtures.down_event_new_pos_1,
47 LogEventFixtures.up_pressed_new_pos_0,
48 LogEventFixtures.up_pressed_new_pos_2,
49 LogEventFixtures.up_pressed_new_pos_1,
50 LogEventFixtures.explicit_select_position_1
52 validate(list, list.serialize(), expectedErr = emptyList())
56 fun `up down actions wrong`() {
58 LogEventFixtures.completion_started_3_items_shown,
59 LogEventFixtures.down_event_new_pos_1,
60 LogEventFixtures.up_pressed_new_pos_0,
61 LogEventFixtures.up_pressed_new_pos_2,
62 LogEventFixtures.up_pressed_new_pos_1,
63 LogEventFixtures.explicit_select_position_0
65 validate(list, expectedOut = emptyList(), expectedErr = list.serialize())
69 fun `selected by typing relaxed conditions`() {
71 LogEventFixtures.completion_started_3_items_shown,
72 LogEventFixtures.type_event_current_pos_0_left_ids_1_2,
73 LogEventFixtures.type_event_current_pos_0_left_id_0,
74 LogEventFixtures.selected_by_typing_0
76 validate(list, expectedOut = list.serialize(), expectedErr = emptyList())
80 fun `selected by typing error`() {
82 LogEventFixtures.completion_started_3_items_shown,
83 LogEventFixtures.type_event_current_pos_0_left_ids_0_1,
84 LogEventFixtures.down_event_new_pos_1,
85 LogEventFixtures.explicit_select_position_1
87 validate(list, expectedOut = list.serialize(), expectedErr = emptyList())
90 private fun validate(list: List<LogEvent>,
91 expectedOut: List<String>,
92 expectedErr: List<String>) {
93 val input: List<String> = list.map { LogEventSerializer.toString(it) }
94 val result = SimpleSessionValidationResult()
95 val separator = InputSessionValidator(result)
96 separator.validate(input)
98 assertThat(result.errorLines).isEqualTo(expectedErr)
99 assertThat(result.validLines).isEqualTo(expectedOut)