Пример #1
0
func TestJavaFormatSpecifierStringForFormatSpecifier(t *testing.T) {
	val := func(dataType model.TranslationFormatDataType,
		index int,
		numDecimals int,
		semanticOrderIndex int) string {
		return java.FormatSpecifierStringForFormatSpecifier(model.NewFormatSpecifierSegment(dataType, numDecimals, semanticOrderIndex), index)
	}

	// Data types
	assert.Equal(t, "{0}", val(model.DataTypeObject, 0, -1, -1), "")
	assert.Equal(t, "{0}", val(model.DataTypeString, 0, -1, -1), "")
	assert.Equal(t, "{0,number}", val(model.DataTypeFloat, 0, -1, -1), "")
	assert.Equal(t, "{0,number,integer}", val(model.DataTypeInteger, 0, -1, -1), "")

	// Semantic order index
	assert.Equal(t, "{0}", val(model.DataTypeObject, 0, -1, 0), "")
	assert.Equal(t, "{77}", val(model.DataTypeObject, 77, -1, 0), "")
	assert.Equal(t, "{0}", val(model.DataTypeObject, 0, -1, 1), "Output index is 0-based while explicit order index is 1-based")
	assert.Equal(t, "{11}", val(model.DataTypeObject, 0, -1, 12), "Output index is 0-based while explicit order index is 1-based")
	assert.Equal(t, "{11}", val(model.DataTypeObject, 77, -1, 12), "Explicit order index overrides actual index")

	// Decimal count
	assert.Equal(t, "{0,number,#}", val(model.DataTypeFloat, 0, 0, -1), "")
	assert.Equal(t, "{0,number,#.#}", val(model.DataTypeFloat, 0, 1, -1), "")
	assert.Equal(t, "{0,number,#.#####}", val(model.DataTypeFloat, 0, 5, -1), "")
	assert.Equal(t, "{2,number,#.#}", val(model.DataTypeFloat, 0, 1, 3), "Decimal count together with semantic order index")
	assert.Equal(t, "{0}", val(model.DataTypeObject, 0, 1, -1), "Decimal count is only for floats")
	assert.Equal(t, "{0}", val(model.DataTypeString, 0, 1, -1), "Decimal count is only for floats")
	assert.Equal(t, "{0,number,integer}", val(model.DataTypeInteger, 0, 1, -1), "Decimal count is only for floats")
}
Пример #2
0
func TestAppleFormatSpecifierStringForFormatSpecifier(t *testing.T) {
	val := func(dataType model.TranslationFormatDataType,
		numDecimals int,
		semanticOrderIndex int) string {
		return apple.FormatSpecifierStringForFormatSpecifier(model.NewFormatSpecifierSegment(dataType, numDecimals, semanticOrderIndex))
	}

	// Data types
	assert.Equal(t, "%@", val(model.DataTypeObject, -1, -1), "")
	assert.Equal(t, "%s", val(model.DataTypeString, -1, -1), "")
	assert.Equal(t, "%f", val(model.DataTypeFloat, -1, -1), "")
	assert.Equal(t, "%d", val(model.DataTypeInteger, -1, -1), "")

	// Semantic order index
	assert.Equal(t, "%f", val(model.DataTypeFloat, -1, 0), "")
	assert.Equal(t, "%1$f", val(model.DataTypeFloat, -1, 1), "")
	assert.Equal(t, "%12$f", val(model.DataTypeFloat, -1, 12), "")

	// Decimal count
	assert.Equal(t, "%.0f", val(model.DataTypeFloat, 0, -1), "")
	assert.Equal(t, "%.1f", val(model.DataTypeFloat, 1, -1), "")
	assert.Equal(t, "%.34f", val(model.DataTypeFloat, 34, -1), "")
	assert.Equal(t, "%3$.1f", val(model.DataTypeFloat, 1, 3), "Decimal count together with semantic order index")
	assert.Equal(t, "%@", val(model.DataTypeObject, 1, -1), "Decimal count is only for floats")
	assert.Equal(t, "%s", val(model.DataTypeString, 1, -1), "Decimal count is only for floats")
	assert.Equal(t, "%d", val(model.DataTypeInteger, 1, -1), "Decimal count is only for floats")
}