Initial testing of Go templates

Published by Karl on

I think using the Go templating functionality should be enough to get a quick solution to this little problem. We’ll have an overall template for the test then sub-templates for each question type, driven by a function per question type.

And for a sample input, we’ll feed it the following XML

<?xml version="1.0" encoding="utf-8"?>
	<question type='r'>
		<part type='h'>しけんは</part>
		<part type='k' answer='3'>来月</part>
		<part type='h'>の</part>
		<part type='k' answer='3'>七月</part>
		<part type='h'>八日</part>
	<question type='w'>
		<part type='h'>きょうは</part>
		<part type='k'>げん</part>
		<part type='k'>き</part>
		<part type='h'>がいいです。</part>
	<question type='r'>
		<part type='k' answer='2'>日本語</part>
		<part type='h'>を</part>
		<part type='k' answer='2'>話</part>
		<part type='h'>せますか?</part>
	<question type='c'>
		<part type='h'>いけんを</part>
		<part type='c' answer='2'>いう</part>
		<part type='h'>。</part>
This is a quick run from the first version of the Go program

The layout needs work, but I think the basic premise will work. Still need to decide how the spacing will work, though hopefully that will resolve it self once the formating comes in instead of place holders.