<commit_before>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/
package org.eclipse.xtext.parsetree.reconstr;

import java.io.IOException;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport;
import org.eclipse.xtext.parsetree.reconstr.impl.TokenStringBuffer;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Indent;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Model;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.TwoOptions;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.TwoRequired;
import org.eclipse.xtext.tests.AbstractGeneratorTest;

public class SerializationErrorTest extends AbstractGeneratorTest {

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		with(SerializationErrorTestLanguageStandaloneSetup.class);
	}

	private TreeConstructionReport ser(EObject obj) throws IOException {
		TokenStringBuffer b = new TokenStringBuffer();
		TreeConstructionReport r;
		try {
			r = getSerializer().serialize(obj, b, null, true);
		} catch (XtextSerializationException e) {
			r = e.getReport();
		}
		// System.out.println("Result:");
		// System.out.println(r);
		// System.out.println();
		// String path = "tmp/" + getName() + ".pdf";
		// new TraceToDot().draw(r, path, "-T pdf");
		return r;
	}

	public void testMissingElement() throws Exception {
		Model m = (Model) getModel("tworequired a b");
		// System.out.println(EmfFormatter.objToStr(m));
		((TwoRequired) m.getTest()).setOne(null);
		TreeConstructionReport r = ser(m);
		assertFalse(r.isSuccess());
		// assertEquals(2, r.getLikelyErrorReasons(3).size());
		// assertTrue(r.toString(), r.getLikelyErrorReasons(1).get(0).contains(
		// "Test(TwoRequired).one is not set"));
		assertTrue(r.toString(), r.toString().contains(
				"TwoRequired.one is not set"));
	}<commit_msg>Integrated the ConcreteSyntaxValidator with the XtextResource and the SerializerUtil. However, it is still disabled by default.<commit_after>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/
package org.eclipse.xtext.parsetree.reconstr;

import java.io.IOException;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport;
import org.eclipse.xtext.parsetree.reconstr.SerializerUtil.SerializationOptions;
import org.eclipse.xtext.parsetree.reconstr.impl.TokenStringBuffer;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Indent;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Model;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.TwoOptions;
import org.eclipse.xtext.parsetree.reconstr.serializationerror.TwoRequired;
import org.eclipse.xtext.tests.AbstractGeneratorTest;

public class SerializationErrorTest extends AbstractGeneratorTest {

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		with(SerializationErrorTestLanguageStandaloneSetup.class);
	}

	private TreeConstructionReport ser(EObject obj) throws IOException {
		TokenStringBuffer b = new TokenStringBuffer();
		TreeConstructionReport r;
		try {
			r = getSerializer().serialize(obj, b, null, new SerializationOptions());
		} catch (XtextSerializationException e) {
			r = e.getReport();
		}
		// System.out.println("Result:");
		// System.out.println(r);
		// System.out.println();
		// String path = "tmp/" + getName() + ".pdf";
		// new TraceToDot().draw(r, path, "-T pdf");
		return r;
	}

	public void testMissingElement() throws Exception {
		Model m = (Model) getModel("tworequired a b");
		// System.out.println(EmfFormatter.objToStr(m));
		((TwoRequired) m.getTest()).setOne(null);
		TreeConstructionReport r = ser(m);
		assertFalse(r.isSuccess());
		// assertEquals(2, r.getLikelyErrorReasons(3).size());
		// assertTrue(r.toString(), r.getLikelyErrorReasons(1).get(0).contains(
		// "Test(TwoRequired).one is not set"));
		assertTrue(r.toString(), r.toString().contains(
				"TwoRequired.one is not set"));
	}
{'fraction_non_alphanumeric': 0.18360253526886117, 'fraction_numerical': 0.0049069719893682275, 'mean_word_length': 5.44532279314888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3962714', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1419, 'n_words': 302}