library(yaml)

args <- NULL; 

# Function to run tests:
# source_lines("/esarchive/scratch/nperez/git/startR/inst/doc/usecase/ex2_1_timedim.R",
#              start = 4, end = 14)
source_lines <- function(file, start, end, ...) {
    file.lines <- scan(file, what = character(), skip = start - 1, 
                       nlines = end - start + 1, sep = '\n')
    file.lines.collapsed <- paste(file.lines, collapse = '\n')
    source(textConnection(file.lines.collapsed), ...)
}

# ------------------------------------------
# Section to check recipes that should work:
args[1] <- "recipes/tests/seasonal_testWorkflow1.yml"
source_lines("OperationalCS.R", start =  14, end = 50)
# Calibration method None --> raw data verification
args[1] <- "recipes/tests/seasonal_testWorkflow4.yml"
source_lines("OperationalCS.R", start =  14, end = 50)
# Calibration: None --> raw data verification
args[1] <- "recipes/tests/seasonal_testWorkflow5.yml"
source_lines("OperationalCS.R", start =  14, end = 50)
# Case Skill_1 and Skill_2 when multiple times needed
args[1] <- "recipes/tests/seasonal_testWorkflow7.yml"
source_lines("OperationalCS.R", start =  14, end = 50)
# Indicator
args[1] <- "recipes/tests/seasonal_testWorkflow8.yml"
source_lines("OperationalCS.R", start =  14, end = 50)

# ------------------------------------------
# Section to check recipes that should fail:
## This should fail because there is no Horizon:
args[1] <- "recipes/tests/seasonal_testWorkflow2.yml"
source_lines("OperationalCS.R", start =  14, end = 50)

## This should fail because there are 2 Calibration options:
args[1] <- "recipes/tests/seasonal_testWorkflow3.yml"
source_lines("OperationalCS.R", start =  14, end = 50)

## This fails because it is not allow repeating the name Skill
args[1] <- "recipes/tests/seasonal_testWorkflow6.yml"
source_lines("OperationalCS.R", start =  14, end = 50)
