func Test_MergeAllRight(t *testing.T) {
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftDB),
		right: model.MakeDatabaseCopy(rightDB),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.Error(t, dbw.MergeBookmarks("", mcw))
	selectSameSide(mcw, "rightSide")
	dbw.Init()
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.Error(t, dbw.MergeInputFields("", mcw))
	selectSameSide(mcw, "rightSide")
	dbw.Init()
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.NoError(t, dbw.MergeInputFields("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	selectSameSide(mcw, "rightSide")
	dbw.Init()
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.NoError(t, dbw.MergeInputFields("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	assert.Error(t, dbw.MergeNotes("", mcw))
	selectSameSide(mcw, "rightSide")
	dbw.Init()
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.NoError(t, dbw.MergeInputFields("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	assert.NoError(t, dbw.MergeNotes("", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	assert.True(t, mergedAllRightDB.Equals(dbw.merged))
}
Merge while selecting all right
package gomobile
import (
	"database/sql"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"
	"github.com/AndreasSko/go-jwlm/model"
	"github.com/stretchr/testify/assert"
)
func Test_MergeMultiCollisionAllRight(t *testing.T) {
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftMultiCollision),
		right: model.MakeDatabaseCopy(rightMultiCollision),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.Error(t, dbw.MergeInputFields("", mcw))
	conflict, err := mcw.NextConflict()
	assert.NoError(t, err)
	assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
	assert.NoError(t, dbw.MergeInputFields("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	conflict, err = mcw.NextConflict()
	assert.NoError(t, err)
	assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
	assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	conflict, err = mcw.NextConflict()
	assert.NoError(t, err)
	assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
	assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	conflict, err = mcw.NextConflict()
	assert.NoError(t, err)
	assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
	assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	conflict, err = mcw.NextConflict()
	assert.NoError(t, err)
	assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	assert.NoError(t, dbw.MergeNotes("", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	assert.True(t, dbw.merged.Equals(rightMultiCollision))
}
func Test_MergeMultiCollisionAllExceptOneRight(t *testing.T) {
	for i := 0; i < 10; i++ {
		dbw := DatabaseWrapper{
			left:  model.MakeDatabaseCopy(leftMultiCollision),
			right: model.MakeDatabaseCopy(rightMultiCollision),
		}
		dbw.Init()
		mcw := &MergeConflictsWrapper{}
		assert.NoError(t, dbw.MergeLocations())
		assert.NoError(t, dbw.MergeBookmarks("", mcw))
		assert.Error(t, dbw.MergeInputFields("", mcw))
		conflict, err := mcw.NextConflict()
		assert.NoError(t, err)
		assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
		assert.NoError(t, dbw.MergeInputFields("", mcw))
		assert.NoError(t, dbw.MergeTags())
		assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
		conflict, err = mcw.NextConflict()
		assert.NoError(t, err)
		assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
		assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
		conflict, err = mcw.NextConflict()
		assert.NoError(t, err)
		assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
		assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
		conflict, err = mcw.NextConflict()
		assert.NoError(t, err)
		assert.NoError(t, mcw.SolveConflict(conflict.Key, "rightSide"))
		assert.Error(t, dbw.MergeUserMarkAndBlockRange("", mcw))
		conflict, err = mcw.NextConflict()
		assert.NoError(t, err)
		assert.NoError(t, mcw.SolveConflict(conflict.Key, "leftSide"))
		assert.NoError(t, dbw.MergeUserMarkAndBlockRange("", mcw))
		assert.NoError(t, dbw.MergeNotes("", mcw))
		assert.NoError(t, dbw.MergeTagMaps())
		expected := model.MakeDatabaseCopy(rightMultiCollision)
		expected.BlockRange = []*model.BlockRange{
			nil,
			{
				BlockRangeID: 1,
				BlockType:    1,
				Identifier:   1,
				StartToken:   sql.NullInt32{3, true},
				EndToken:     sql.NullInt32{3, true},
				UserMarkID:   1,
			},
		}
		assert.True(t, dbw.merged.Equals(expected))
	}
}
func Test_MergeMultiCollisionAutoSolver(t *testing.T) {
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftMultiCollision),
		right: model.MakeDatabaseCopy(rightMultiCollision),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeInputFields("chooseRight", mcw))
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("chooseRight", mcw))
	assert.NoError(t, dbw.MergeNotes("", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	assert.True(t, dbw.merged.Equals(rightMultiCollision))
}
func Test_MergeNwt(t *testing.T) {
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftNwtDB),
		right: model.MakeDatabaseCopy(rightNwtDB),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeInputFields("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeBookmarks("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeNotes("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	assert.True(t, dbw.merged.Equals(mergedAllLeftNwtDB))
}
func Test_MergeNwtDifferentDocID(t *testing.T) {
	tmp, err := ioutil.TempDir("", "go-jwlm")
	assert.NoError(t, err)
	defer os.RemoveAll(tmp)
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftDBNwtWithDifferentDocID),
		right: model.MakeDatabaseCopy(rightDBNwtWithDifferentDocID),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeInputFields("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeBookmarks("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeNotes("chooseLeft", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	newBackup := filepath.Join(tmp, "test.jwlibrary")
	assert.NoError(t, dbw.ExportMerged(newBackup))
	newDB := &model.Database{}
	assert.NoError(t, newDB.ImportJWLBackup(newBackup))
	assert.True(t, newDB.Equals(mergedDBNwtWithDifferentDocID))
}
var leftMultiCollision = &model.Database{
	BlockRange: []*model.BlockRange{
		nil,
		{
			BlockRangeID: 1,
			BlockType:    1,
			Identifier:   1,
			StartToken:   sql.NullInt32{0, true},
			EndToken:     sql.NullInt32{0, true},
			UserMarkID:   1,
		},
		{
			BlockRangeID: 2,
			BlockType:    1,
			Identifier:   1,
			StartToken:   sql.NullInt32{1, true},
			EndToken:     sql.NullInt32{1, true},
			UserMarkID:   2,
		},
		{
			BlockRangeID: 3,
			BlockType:    1,
			Identifier:   1,
			StartToken:   sql.NullInt32{2, true},
			EndToken:     sql.NullInt32{2, true},
			UserMarkID:   3,
		},
		{
			BlockRangeID: 4,
			BlockType:    1,
			Identifier:   1,
			StartToken:   sql.NullInt32{3, true},
			EndToken:     sql.NullInt32{3, true},
			UserMarkID:   4,
		},
	},
	Bookmark: []*model.Bookmark{nil},
	InputField: []*model.InputField{
		nil,
		{
			LocationID: 1,
			TextTag:    "a1",
			Value:      "a1",
		},
		{
			LocationID: 1,
			TextTag:    "a2",
			Value:      "a2",
		},
	},
	Location: []*model.Location{
		nil,
		{
			LocationID:    1,
			BookNumber:    sql.NullInt32{1, true},
			ChapterNumber: sql.NullInt32{1, true},
			KeySymbol:     sql.NullString{"nwtsty", true},
			MepsLanguage:  2,
			LocationType:  0,
			Title:         sql.NullString{"1. Mose 1", true},
		},
	},
	Note:   []*model.Note{nil},
	Tag:    []*model.Tag{nil},
	TagMap: []*model.TagMap{nil},
	UserMark: []*model.UserMark{
		nil,
		{
			UserMarkID:   1,
			ColorIndex:   1,
			LocationID:   1,
			StyleIndex:   1,
			UserMarkGUID: "1",
		},
		{
			UserMarkID:   2,
			ColorIndex:   1,
			LocationID:   1,
			StyleIndex:   1,
			UserMarkGUID: "2",
		},
		{
			UserMarkID:   3,
			ColorIndex:   1,
			LocationID:   1,
			StyleIndex:   1,
			UserMarkGUID: "3",
		},
		{
			UserMarkID:   4,
			ColorIndex:   1,
			LocationID:   1,
			StyleIndex:   1,
			UserMarkGUID: "4",
		},
	},
}
var rightMultiCollision = &model.Database{
	BlockRange: []*model.BlockRange{
		nil,
		{
			BlockRangeID: 1,
			BlockType:    1,
			Identifier:   1,
			StartToken:   sql.NullInt32{0, true},
			EndToken:     sql.NullInt32{20, true},
			UserMarkID:   1,
		},
	},
	Bookmark: []*model.Bookmark{nil},
	InputField: []*model.InputField{
		nil,
		{
			LocationID: 1,
			TextTag:    "a1",
			Value:      "different",
		},
		{
			LocationID: 1,
			TextTag:    "a2",
			Value:      "a2",
		},
		{
			LocationID: 1,
			TextTag:    "b1",
			Value:      "b1",
		},
	},
	Location: []*model.Location{
		nil,
		{
			LocationID:    1,
			BookNumber:    sql.NullInt32{1, true},
			ChapterNumber: sql.NullInt32{1, true},
			KeySymbol:     sql.NullString{"nwtsty", true},
			MepsLanguage:  2,
			LocationType:  0,
			Title:         sql.NullString{"1. Mose 1", true},
		},
	},
	Note:   []*model.Note{nil},
	Tag:    []*model.Tag{nil},
	TagMap: []*model.TagMap{nil},
	UserMark: []*model.UserMark{
		nil,
		{
			UserMarkID:   1,
			ColorIndex:   1,
			LocationID:   1,
			StyleIndex:   1,
			UserMarkGUID: "1R",
		},
	},
}
func Test_MergeWithEmpty(t *testing.T) {
	dbw := DatabaseWrapper{
		left:  model.MakeDatabaseCopy(leftDB),
		right: model.MakeDatabaseCopy(emptyDB),
	}
	dbw.Init()
	mcw := &MergeConflictsWrapper{}
	assert.NoError(t, dbw.MergeLocations())
	assert.NoError(t, dbw.MergeInputFields("", mcw))
	assert.NoError(t, dbw.MergeBookmarks("", mcw))
	assert.NoError(t, dbw.MergeTags())
	assert.NoError(t, dbw.MergeUserMarkAndBlockRange("", mcw))
	assert.NoError(t, dbw.MergeNotes("", mcw))
	assert.NoError(t, dbw.MergeTagMaps())
	assert.True(t, dbw.left.Equals(dbw.merged))
}