package com.jetbrains.edu.yaml.inspections
import com.jetbrains.edu.learning.courseFormat.BinaryContents
import com.jetbrains.edu.learning.courseFormat.CourseMode
import com.jetbrains.edu.learning.courseFormat.tasks.choice.ChoiceOptionStatus
import com.jetbrains.edu.learning.yaml.YamlMapper.CURRENT_YAML_VERSION
import org.jetbrains.yaml.schema.YamlJsonSchemaHighlightingInspection
import org.junit.Test
class YamlJsonSchemaInspection : YamlInspectionsTestBase(YamlJsonSchemaHighlightingInspection::class) {
@Test
fun `test course with one wrong property`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {}
}
testHighlighting(getCourse(), """
|title: Test Course
|type: coursera
|language: Russian
|summary: sum
|wrong_property: prop
|programming_language: Plain text
|programming_language_version: 1.42
|environment: Android
|content:
|- lesson1
|yaml_version: $CURRENT_YAML_VERSION
|
""".trimMargin("|"))
}
@Test
fun `test course with marketplace course type`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {}
}
testHighlighting(getCourse(), """
|title: Test Course
|type: marketplace
|language: Russian
|summary: sum
|wrong_property: prop
|programming_language: Plain text
|programming_language_version: 1.42
|environment: Android
|content:
|- lesson1
|yaml_version: $CURRENT_YAML_VERSION
|
""".trimMargin("|"))
}
@Test
fun `test course without yaml_version`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {}
}
testHighlighting(getCourse(), """
|title: Test Course
|type: coursera
|language: Russian
|summary: sum
|programming_language: Plain text
|programming_language_version: 1.42
|environment: Android
|content:
|- lesson1
|
""".trimMargin("|"))
}
@Test
fun `test section with one wrong property`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
section {
lesson {}
}
}
testHighlighting(getCourse().items[0], """
|wrong_property: prop
|content:
|- lesson1
""".trimMargin("|"))
}
@Test
fun `test lesson with one wrong property`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {
eduTask { }
}
}
testHighlighting(getCourse().items[0], """
|type: framework
|wrong_property: prop
|content:
|- task1
""".trimMargin("|"))
}
@Test
fun `test edu task with wrong properties on each level`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {
eduTask {
taskFile("Test.java", "
f()
") {
placeholder(index = 0, possibleAnswer = "test")
}
}
}
lesson {
eduTask {
taskFile("Test.java", "f()
") {
placeholder(index = 0, placeholderText = "type here", dependency = "lesson1#task1#Test.java#1")
}
}
}
}
testHighlighting(findTask(1, 0), """
|type: edu
|wrong_property: prop
|files:
|- name: Test.java
| visible: true
| placeholders:
| - offset: 0
| length: 3
| wrong_property: prop
| placeholder_text: type here
| dependency:
| lesson: lesson1
| task: task1
| file: Test.java
| wrong_property: prop
| placeholder: 1
| is_visible: true
|""".trimMargin("|"))
}
@Test
fun `test choice task with wrong properties on each level`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {
choiceTask(choiceOptions = mapOf("1" to ChoiceOptionStatus.CORRECT, "2" to ChoiceOptionStatus.INCORRECT)) {
taskFile("Test.java", "")
}
}
}
testHighlighting(findTask(0, 0), """
|type: choice
|wrong_property: prop
|is_multiple_choice: false
|options:
|- text: 1
| is_correct: true
|- text: 2
| is_correct: false
| wrong_property: prop
|files:
|- name: Test.java
| wrong_property: prop
| visible: true
|""".trimMargin("|"))
}
@Test
fun `courses can have binary additional files`() {
val course = courseWithFiles(courseMode = CourseMode.EDUCATOR) {
additionalFile("a.png", BinaryContents.EMPTY)
}
testHighlighting(course,
"""
|title: Test Course
|type: marketplace
|language: Russian
|summary: sum
|programming_language: Plain text
|environment: Android
|content:
|- lesson1
|additional_files:
| - name: a.png
| is_binary: true
|yaml_version: $CURRENT_YAML_VERSION
|""".trimMargin("|")
)
}
@Test
fun `tasks can have binary additional files`() {
courseWithFiles(courseMode = CourseMode.EDUCATOR) {
lesson {
eduTask {
taskFile("Test.java", BinaryContents.EMPTY)
}
}
}
testHighlighting(findTask(0, 0),
"""
|type: edu
|files:
|- name: Test.java
| is_binary: true
| visible: true
|""".trimMargin("|")
)
}
}