#!/usr/bin/expect

set timeout 5
set env(NO_COLOR) 1

source  "$env(BATS_CWD)/helper/common_expect_functions.tcl"

spawn dolt add --patch

# Header Regex for:
# Table                              Added / Modified / Removed
# =====                              =====   ========   =======
# colors                             1       1          1
# coordinates                        1       1          1
# names                              1       1          1
set header {.*Table\s+Added\s+/\s+Modified\s+/\s+Removed\s+=+\s+=+\s+=+\s+=+\s+colors\s+1\s+1\s+1\s+coordinates\s+1\s+1\s+1\s+names\s+1\s+1\s+1.*}

expect_with_defaults_2 $header                                      {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| - | 2  | Green | 0   | 255   | 0    |}    {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
expect_with_defaults_2 {| > | 3  | SkyBlue | 0   | 128   | 255  |}  {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| - | 2  | 3.3 | 4.4 |}                     {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }

# Regex to match updated counts.
# Table                              Added / Modified / Removed
# =====                              =====   ========   =======
# colors                             0       0          1
# coordinates                        1       1          1
# names                              1       1          1
set header {.*Table\s+Added\s+/\s+Modified\s+/\s+Removed\s+=+\s+=+\s+=+\s+=+\s+colors\s+0\s+0\s+1\s+coordinates\s+1\s+1\s+1\s+names\s+1\s+1\s+1.*}

expect_with_defaults_2 $header                                      {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| - | 2  | 3.3 | 4.4 |}                     {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
expect_with_defaults_2 {| > | 3  | 5.5 | 100.001 |}                 {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| \+ | 4  | 42.24 | 23.32 |}                {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }

# Regex to match updated counts, and no colors table:
# Table                              Added / Modified / Removed
# =====                              =====   ========   =======
# coordinates                        1       0          1
# names                              1       1          1
set header {.*Table\s+Added\s+/\s+Modified\s+/\s+Removed\s+=+\s+=+\s+=+\s+=+\s+coordinates\s+1\s+0\s+1\s+names\s+1\s+1\s+1.*}

expect_with_defaults_2 $header                                      {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| \+ | 4  | 42.24 | 23.32 |}                {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
expect_with_defaults_2 {| > | 1  | joey |}                          {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| - | 2  | sami |}                          {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "s\r"; }

# Regex for:
# Table                              Added / Modified / Removed
# =====                              =====   ========   =======
# coordinates                        1       0          0
# names                              1       0          1
set header {.*Table\s+Added\s+/\s+Modified\s+/\s+Removed\s+=+\s+=+\s+=+\s+=+\s+coordinates\s+1\s+0\s+0\s+names\s+1\s+0\s+1.*}

expect_with_defaults_2 $header                                      {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }
expect_with_defaults_2 {| - | 2  | sami |}                          {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; }
expect_with_defaults_2 {| \+ | 4  | john |}                         {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; }

expect eof
exit
