!! functionhooks
convert
!! endfunctionhooks
!! test
Simple conversion
!! input
{{#convert: 10 m | km }}
!!result
0.01 kilometres
!! end
!! test
Position and formatting of numbers and units
!! input
*{{#convert: 10 m | km }}
*{{#convert: 10m | km }}
*{{#convert: 10 km | m }}
*{{#convert: 10-km | m }}
*{{#convert: 10E2 km | m }}
*{{#convert: 10E-2 km | m }}
*{{#convert: 10.0E2 km | m }}
*{{#convert: 10.0E2.5 km | m }}
!! result
- 0.01 kilometres
- 0.01kilometres
- 10,000 metres
- 10,000-metres
- 1,000,000 metres
- 100 metres
- 1,000,000 metres
- 1,000,000.5,000 metres
!! end
!! test
Precision 1
!! input
*{{#convert: 10 m | km }}
*{{#convert: 11 m | km }}
*{{#convert: 12 m | km }}
*{{#convert: 13 m | km }}
*{{#convert: 14 m | km }}
*{{#convert: 15 m | km }}
*{{#convert: 16 m | km }}
*{{#convert: 17 m | km }}
*{{#convert: 18 m | km }}
*{{#convert: 19 m | km }}
*{{#convert: 20 m | km }}
!! result
- 0.01 kilometres
- 0.011 kilometres
- 0.012 kilometres
- 0.013 kilometres
- 0.014 kilometres
- 0.015 kilometres
- 0.016 kilometres
- 0.017 kilometres
- 0.018 kilometres
- 0.019 kilometres
- 0.02 kilometres
!! end
!! test
Precision 2
!! input
*{{#convert: 10.0 m | km }}
*{{#convert: 10.1 m | km }}
*{{#convert: 10.2 m | km }}
*{{#convert: 10.3 m | km }}
*{{#convert: 10.4 m | km }}
*{{#convert: 10.5 m | km }}
*{{#convert: 10.6 m | km }}
*{{#convert: 10.7 m | km }}
!! result
- 0.0100 kilometres
- 0.0101 kilometres
- 0.0102 kilometres
- 0.0103 kilometres
- 0.0104 kilometres
- 0.0105 kilometres
- 0.0106 kilometres
- 0.0107 kilometres
!! end
!! test
String interpolation
!! input
{{#convert: 25, 26, 27, 28, 29, and 30 km }}
!! result
25,000, 26,000, 27,000, 28,000, 29,000, and 30,000 metres
!! end
!! test
Precision 3
!! input
{{#convert: 25, 26, 27, 28, 29, and 30 miles }}
!! result
40,000, 42,000, 43,000, 45,000, 47,000, and 50,000 metres
!! end
!! test
Precision 4
!! input
{{#convert:35000, 35E3, 35.0E3, 350E2, 3.500E4, 35000E0, 350000E-1 m | km }}
!! result
35, 35, 35.0, 35, 35.00, 35, 35 kilometres
!! end
!! test
#sourceunit
!!input
*{{#convert: 25 | #sourceunit = km }}
*{{#convert: 25 | #sourceunit=km }}
*{{#convert: 25 | #sourceunit = km | #sourceunit = mm }}
*{{#convert: 25 | #sourceunit = km | cm }}
!! result
- 25,000 metres
- 25,000 metres
- 0.025 metres
- 2,500,000 centimetres
!! end
!! test
Precision overrides
!!input
*{{#convert: 1 mi | #dp = 0 }}
*{{#convert: 1 mi | #dp=1 }}
*{{#convert: 1 mi | #dp = -2 }}
*{{#convert: 1 mi | #dp = 5 }}
*{{#convert: 1 mi | #dp = -8 }}
*{{#convert: 1 mi | #sf = 0 }}
*{{#convert: 1 mi | #sf=1 }}
*{{#convert: 1 mi | #sf = 3 }}
*{{#convert: 1 mi | #sf = 5 }}
*{{#convert: 1 mi | #sf = -8 }}
!! result
- 1,609 metres
- 1,609.3 metres
- 1,600 metres
- 1,609.344 metres
- 0 metres
- 2,000 metres
- 2,000 metres
- 1,610 metres
- 1,609.3 metres
- 2,000 metres
!! end
!! test
Errors
!! input
*{{#convert: 25 | km }}
*{{#convert: 25 foobars | mi }}
*{{#convert: 25 mi | #sourceunit = foobar }}
*{{#convert: 25 km | s }}
*{{#convert: 25 km/Pa | m/Pa }}
*{{#convert: 25 km/s/l }}
*{{#convert: 25 km/m3 }}
!! result
- Error: No source unit given.
- Error: Unknown unit "foobars".
- Error: Unknown unit "foobar".
- Error: Cannot convert between units of "length" and "time".
- Error: Invalid compound unit "length/pressure".
- Error: Cannot parse double compound units like "km/s/l".
- Error: Invalid compound unit "length/volume".
!! end
!! test
#sourceunit = #targetunit
!! input
*{{#convert: 25 km | #targetunit = #sourceunit }}
*{{#convert: 25 km | #sourceunit = #targetunit }}
!! result
- 25 kilometres
- 25 kilometres
!! end
!! test
#language
!! input
*{{#convert: 10 m | km | #language=en-gb }}
*{{#convert: 10m | km | #language = en }}
*{{#convert: 10 km | m |#language=en}}
*{{#convert: 10 Pa | mmHg | #language = fr }}
!! result
- 0.01 kilometres
- 0.01kilometers
- 10,000 meters
- 0.1 millimètre de mercure
!! end
!! test
Case sensitivity
!! input
*{{#convert: 10 mm | m }}
*{{#convert: 10 Mm | m }}
*{{#convert: 10 km | Mm }}
*{{#convert: 10 Pa | mmHg }}
*{{#convert: 10 pa | mmHg }}
!! result
- 0.01 metres
- 10,000,000 metres
- 0.01 megametres
- 0.1 millimetres of mercury
- Error: Unknown unit "pa".
!! end